From: duke on
On Feb 28, 8:16 am, "Henning" <computer_h...(a)coldmail.com> wrote:
> "Anita" <no_s...(a)mail.com> skrev i meddelandetnews:dxvin.58165$G_2.40207(a)newsfe15.iad...
>
> > I'm trying to use a simple function, and pass two integer values to it.
>
> > Function Readb(intDev as Integer, intBank As Integer)
> >   Do something
> > End Function
>
> > Using   Readb 2,0    works fine, but
> > Using Readb txtBank.text    results in an 'Argument not optional' error
> > message.
> > in the text box is 2,0 or 2, 0  - either one,  Argument not optional.
>
> > What am I missing?
>
> > Any suggestions appreciated.
>
> Use Val(txtBank.text) or Cint(txtBank.text).
>
> A TextBox Value is String, the Function expects an Integer.
>
> /Henning

You are missing the word "Optional" for each time you have an
optional input in the Function.

It should read:

Function Readb(intDev as Integer, Optional intBank As Integer)

Have a Good Day
From: Henning on

"Bob Butler" <noway(a)nospam.ever> skrev i meddelandet
news:eW6XT1IuKHA.1796(a)TK2MSFTNGP02.phx.gbl...
>
> "Anita" <no_spam(a)mail.com> wrote in message
> news:dxvin.58165$G_2.40207(a)newsfe15.iad...
>> I'm trying to use a simple function, and pass two integer values to it.
>>
>> Function Readb(intDev as Integer, intBank As Integer)
>> Do something
>> End Function
>>
>> Using Readb 2,0 works fine, but
>> Using Readb txtBank.text results in an 'Argument not optional' error
>> message.
>> in the text box is 2,0 or 2, 0 - either one, Argument not optional.
>>
>> What am I missing?
>
> txtBank.Text returns a single string; that string may contain a comma but
> that doesn't make it 2 values, it's still just a single string
>
> x=instr(1,txtBank.Text,",")
> readb cint(left$(txtbank.text,x-1)),Cint(mid$(txtBank.Text,x+1))
>
> although you should also have some checks to ensure there is a comma and
> that there is a numeric value on each side within the string.
>

Ooops, missed that one...

You can also change the declaration of the Function to accept a String as
the argument, and do the splitting/checking inside the Function. Also
declare the return type, or if none change it to a Sub.

/Henning




From: Nobody on
"Anita" <no_spam(a)mail.com> wrote in message
news:dxvin.58165$G_2.40207(a)newsfe15.iad...
> I'm trying to use a simple function, and pass two integer values to it.
>
> Function Readb(intDev as Integer, intBank As Integer)
> Do something
> End Function
>
> Using Readb 2,0 works fine, but
> Using Readb txtBank.text results in an 'Argument not optional' error
> message.
> in the text box is 2,0 or 2, 0 - either one, Argument not optional.
>
> What am I missing?
>
> Any suggestions appreciated.

VB doesn't support such constructs. What is happening in you case is that VB
takes "txtBank.text" as one parameter of type String, and coerce the type to
Integer. It's equivalent of using:

Readb CInt(txtBank.text)

So as far as VB is concerned, the second argument is missing. So you need to
parse the string and supply two arguments to the function. One way is by
using InStr(), another by using Split(), then use Val(), or CInt() to
convert the String value to Integer.



From: Anita on
"Anita" <no_spam(a)mail.com> wrote in message
news:HEwin.52388$0N3.23917(a)newsfe09.iad...
>
> "Bob Butler" <noway(a)nospam.ever> wrote in message
> news:eW6XT1IuKHA.1796(a)TK2MSFTNGP02.phx.gbl...
>>
>> "Anita" <no_spam(a)mail.com> wrote in message
>> news:dxvin.58165$G_2.40207(a)newsfe15.iad...
>>> I'm trying to use a simple function, and pass two integer values to it.
>>>
>>> Function Readb(intDev as Integer, intBank As Integer)
>>> Do something
>>> End Function
>>>
>>> Using Readb 2,0 works fine, but
>>> Using Readb txtBank.text results in an 'Argument not optional' error
>>> message.
>>> in the text box is 2,0 or 2, 0 - either one, Argument not optional.
>>>
>>> What am I missing?
>>
>> txtBank.Text returns a single string; that string may contain a comma but
>> that doesn't make it 2 values, it's still just a single string
>>
>> x=instr(1,txtBank.Text,",")
>> readb cint(left$(txtbank.text,x-1)),Cint(mid$(txtBank.Text,x+1))
>>
>> although you should also have some checks to ensure there is a comma and
>> that there is a numeric value on each side within the string.
>
> Thank you! That worked.
>
> This came to this simple test, but my final code will pull these two
> values from a database as the code runs.
> Like: 1,0 1,1 2,0 2,1,...6,0, etc.
>
> Possibly like:
> x=instr(1,txtBank.Text,",") <-- not sure how to handle
>
> readb cint(left$(RS!Dev,x-1)),Cint(mid$(RS!Bank.Text,x+1)) <-- Sort of
> like this
>

Although it may be much simpler then taking values from a database.

Possibly: Readb RS!Dev, RS!Bank (or variables = to data values)


From: duke on
On Feb 28, 8:02 am, "Anita" <no_s...(a)mail.com> wrote:
> I'm trying to use a simple function, and pass two integer values to it.
>
> Function Readb(intDev as Integer, intBank As Integer)
>    Do something
> End Function
>
> Using   Readb 2,0    works fine, but
> Using Readb txtBank.text    results in an 'Argument not optional' error
> message.
> in the text box is 2,0 or 2, 0  - either one,  Argument not optional.
>
> What am I missing?
>
> Any suggestions appreciated.


Sorry, I should have read closer... If you want to make bothe optional
it would have to read:

Function Readb(Optional intDev as Integer, Optional intBank As
Integer)

Have a good day