locked
Integer data type in text box RRS feed

  • Question

  • User546194788 posted

    There is a column [VisitID] in table OFFICE_VISIT which data type is integer.

    There is a text box will store data from column [VisitID]

    How to declare variable for this text box?

    For example, which code is correct below?

    dim visitid as string=txtVisitID.text

    Or

    dim visitid as integer = cint(txtVisitID.text)

    Wednesday, February 13, 2019 1:42 PM

All replies

  • User475983607 posted

    There is a column [VisitID] in table OFFICE_VISIT which data type is integer.

    There is a text box will store data from column [VisitID]

    How to declare variable for this text box?

    For example, which code is correct below?

    dim visitid as string=txtVisitID.text

    Or

    dim visitid as integer = cint(txtVisitID.text)

    I recommend Integer.TryParse().

    https://www.dotnetperls.com/parse-vbnet

    Wednesday, February 13, 2019 1:52 PM
  • User-1716253493 posted

    AFAIK, in VB there is auto convert value so you can do

    dim visitid as integer = txtVisitID.text

    the text (string) will be converted to an integer because visitid is an integer

    If you are not sure txtVisitedID will always contain a number you can use validator or tryparse like another previous post

    visitid type is depend what will be done with the variable

    If you want to calculate the value or pass the value for db parameter you can use numeric type

    If you want to manipulate string or make a query you can use string

    Thursday, February 14, 2019 1:38 AM
  • User-1174608757 posted

    Hi aspfun,

    According to your description, I suggest you to use tostring() to convert the datatype of column data. Else , since you want to set the value of text box, you should put the txtVisitID.text on the left side. Here is the code ,I hope it could help you.

    Dim a As Integer = 32
    txtVisitID.Text = a.ToString()

    Best Regards

    Wei Zhang

    Thursday, February 14, 2019 5:37 AM