DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Retrieve numeric value from EditBox

Highlighted

Hi All,

I have an issue while trying to get EditBox.text and assigning it to variable. It throws an error regarding type mismatch when I try it in this way:

dim DummyNumber 

DummyNumber  = EditBox.text

One workaround I found was assigning Variable property to given edit box in dialog editor properties, hovewer, this also required defining this variable as global variable in script which was calling given dialog, which seems impractical to me, since this way I would be forced to define global variable both in dialog and script everytime I try to use edit box for numbers. Is there any faster way to do it, perhaps some conversion step which would remove type mismatch between DummyNumber  and EditBox.text? Any suggestions would be welcome.

0 Kudos
Message 1 of 5
(340 Views)

Hi Rashek,

 

What is the error you're getting?  A VBScript variant variable declared in the SUDialog should be happy to receive the TextBox.Text property value.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 2 of 5
(314 Views)

Thank you for reply Brad_Turpin,

unfortunately, when I was asking question, I was a little bit overworked, looking at it now, I see I didnt ask what I had in mind Smiley Happy . So once more: What I am actually trying, is taking a text out of two different edit boxes, multuply these text (as numbers) and assign them to another edit box. Essentialy, during dialog window, user wants to write values to two different boxes and see their multiple in the third. What I am struggling with actually isnt assigning text values to dim´s, but multiplying those dim´s:

dim a, b, c
a = FirstBox.Text
b = SecondBox.Text
c = a * b

ThirdBox.Text = c

I understand there is type mismatch during multiplication, but I found no way so far to get rid of it.

0 Kudos
Message 3 of 5
(306 Views)

Hi Rashek,

 

Actually, that should work fine, so long as the text values entered into the two text boxes can both be interpreted as numbers.  VBScript automatically applies the needed subtype conversions.  The code you submit will run if "a" and "b" both contain text values that can be automatically converted to numbers when you execute "c = a * b".  Again, what is the error message you're getting?

 

My best guess is that you need to add a testing line to check the input values before performing the multiplication:

 

IF IsNumeric(a) AND IsNumeric(b) THEN
  c = a * b
ELSE
  ' do something else
END IF

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Message 4 of 5
(302 Views)

First of all, I would like to thank you Brad, it finally works Smiley Happy

Second of all, it still doesnt make any sense to me, since the only thing I changed in code was what you suggested. IF case gets activated all the time. My understanding (obviously wrong) is that when IF condition gets activated 100% time, it should not change the code at all compared to what you do when it is not. Yet now I am not getting the error I was getting before with the same code being executed.

0 Kudos
Message 5 of 5
(249 Views)