Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 686

"checking a textbox is numerical before converting it" - How to do this succinctly?

$
0
0
Hi,

My Environment is Windows 7, 3rd party VBScript Engine and MS Forms.

I'm doing "isnumeric" checks on a load of values in textboxes and listviews before doing a "CInt" on each of them.

What's the most compact way of doing this.
I started off like this:

Code:

            if IsNumeric(txtPositionsTakenAtTemperature.Text) then
                singPositionsTakenAtTemperature = CSng(txtPositionsTakenAtTemperature.Text)
            else
                msgbox("'Sample Positions taken at' is blank or is not a number")
                exit sub
            end if


and moved onto this until I realised it would display an error, but then move on the next textbox:

Code:

subAddNumberToLV alCalibrationTemperatures, txtCalibrateTempStart
subAddNumberToLV alCalibrationX, txtCalibrateX
subAddNumberToLV alCalibrationY, txtCalibrateY

Code:

sub subAddNumberToLV( ByRef lvListView, ByRef strItem)

    if IsNumeric(strItem) then
        lvListView.Add(CSng(strItem))
    else
        msgbox(strItem & " is not a number")
        exit sub
    end if

End Sub

I could set an error flag in the sub and check it after every time I call subAddNumberToLV, but then it makes the code very bulky.
I don't have a controls container which I could loop through.
I did raise an error in the sub, but that stopped the code completely and closed the form which means the user would need to type everything in again.

Any thoughts?

Thanks

Kristian

Viewing all articles
Browse latest Browse all 686

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>