Need help converting a number to words - vb.net

I am trying to convert a number to a word from a RDLC report:
Public Shared Function changeToWords(ByVal numb As [String]) As [String]
Dim val As [String] = ""
Dim wholeNo As [String] = numb
Dim points As [String] = ""
Dim andStr As [String] = ""
Dim pointStr As [String] = ""
Dim endStr As [String] = ""
Try
Dim decimalPlace As Integer = numb.IndexOf(".")
If decimalPlace > 0 Then
wholeNo = numb.Substring(0, decimalPlace)
points = numb.Substring(decimalPlace + 1)
If Convert.ToInt32(points) > 0 Then
andStr = "point"
' just to separate whole numbers from points
pointStr = translateCents(points)
End If
End If
val = [String].Format("{0} {1}{2} {3}", translateWholeNumber(wholeNo).Trim(), andStr, pointStr, endStr)
Catch
End Try
Return val
End Function
Private Shared Function translateWholeNumber(ByVal number As [String]) As [String]
Dim word As String = ""
Try
Dim beginsZero As Boolean = False
'tests for 0XX
Dim isDone As Boolean = False
'test if already translated
Dim dblAmt As Double = (Convert.ToDouble(number))
'if ((dblAmt > 0) && number.StartsWith("0"))
If dblAmt > 0 Then
'test for zero or digit zero in a nuemric
beginsZero = number.StartsWith("0")
Dim numDigits As Integer = number.Length
Dim pos As Integer = 0
'store digit grouping
Dim place As [String] = ""
'digit grouping name:hundres,thousand,etc...
Select Case numDigits
Case 1
'ones' range
word = ones(number)
isDone = True
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 2
'tens' range
word = tens(number)
isDone = True
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 3
'hundreds' range
pos = (numDigits Mod 3) + 1
place = " Hundred "
Exit Select
' TODO: might not be correct. Was : Exit Select
'thousands' range
Case 4, 5, 6
pos = (numDigits Mod 4) + 1
place = " Thousand "
Exit Select
' TODO: might not be correct. Was : Exit Select
'millions' range
Case 7, 8, 9
pos = (numDigits Mod 7) + 1
place = " Million "
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 10
'Billions's range
pos = (numDigits Mod 10) + 1
place = " Billion "
Exit Select
Case Else
' TODO: might not be correct. Was : Exit Select
'add extra case options for anything above Billion...
isDone = True
Exit Select
' TODO: might not be correct. Was : Exit Select
End Select
If Not isDone Then
'if transalation is not done, continue...(Recursion comes in now!!)
word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos))
'check for trailing zeros
If beginsZero Then
word = " and " & word.Trim()
End If
End If
'ignore digit grouping names
If word.Trim().Equals(place.Trim()) Then
word = ""
End If
End If
Catch
End Try
Return word.Trim()
End Function
Private Shared Function tens(ByVal digit As [String]) As [String]
Dim digt As Integer = Convert.ToInt32(digit)
Dim name As [String] = Nothing
Select Case digt
Case 10
name = "Ten"
Exit Select
' TODO: might not be correct. Was : Exit Select \
Case 11
name = "Eleven"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 12
name = "Twelve"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 13
name = "Thirteen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 14
name = "Fourteen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 15
name = "Fifteen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 16
name = "Sixteen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 17
name = "Seventeen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 18
name = "Eighteen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 19
name = "Nineteen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 20
name = "Twenty"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 30
name = "Thirty"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 40
name = "Fourty"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 50
name = "Fifty"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 60
name = "Sixty"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 70
name = "Seventy"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 80
name = "Eighty"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 90
name = "Ninety"
Exit Select
Case Else
' TODO: might not be correct. Was : Exit Select
If digt > 0 Then
name = (Convert.ToString(tens(digit.Substring(0, 1) & "0")) & " ") & Convert.ToString(ones(digit.Substring(1)))
End If
Exit Select
' TODO: might not be correct. Was : Exit Select
End Select
Return name
End Function
Private Shared Function ones(ByVal digit As [String]) As [String]
Dim digt As Integer = Convert.ToInt32(digit)
Dim name As [String] = ""
Select Case digt
Case 1
name = "One"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 2
name = "Two"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 3
name = "Three"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 4
name = "Four"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 5
name = "Five"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 6
name = "Six"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 7
name = "Seven"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 8
name = "Eight"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 9
name = "Nine"
Exit Select
' TODO: might not be correct. Was : Exit Select
End Select
Return name
End Function
Private Shared Function translateCents(ByVal cents As [String]) As [String]
Dim cts As [String] = ""
Dim digit As [String] = ""
Dim engOne As [String] = ""
For i As Integer = 0 To cents.Length - 1
digit = cents(i).ToString()
If digit.Equals("0") Then
engOne = "Zero"
Else
engOne = ones(digit)
End If
cts += " " & engOne
Next
Return cts
End Function
I am getting the wrong output from the conversion.
For 52001 the given output is Fifty Two Thousand and Hundred One.
However, it should be Fifty Two Thousand and One.

You'll need to add a conditional statement to modify your string concatenation behavior when the beginning of your substring is a zero.
'if transalation is not done, continue...(Recursion comes in now!!)
If (number.Substring(0, 1) = "0") Then
word = translateWholeNumber(number.Substring(pos))
Else
word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos))
End If
Edit: Doing this breaks output if the original string sent to changeToWords begins with any zeros. To rectify that condition, you can trim leading zeros, before the string is processed:
Dim wholeNo As [String] = numb.TrimStart("0"c)

Just change this line:
If Not isDone Then
'if transalation is not done, continue...(Recursion comes in now!!)
word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos))
'check for trailing zeros
If beginsZero Then
word = translateWholeNumber(number.Substring(0, pos))+ " and " + translateWholeNumber(number.Substring(pos))
End If
End If

Related

InputBox not allowing certain ASCII control characters

Currently working with this string that has embedded ASCII control charters.
[)><RS>06<GS>17V0B100<GS>1PRID-001-A1<GS>S99999<RS><EOT>
Below filters out the record separators correctly
i = InputBox("Test") 'i = [)><RS>06<GS>17V0B100<GS>1PRID-001-A1<GS>S99999<RS><EOT>
i = Split(i, Chr(30))
'i(1) = 0617V0B1001PRID-001-A1S99999
But group separators do not. Why does the below not split?
i = InputBox("Test") 'i = [)><RS>06<GS>17V0B100<GS>1PRID-001-A1<GS>S99999<RS><EOT>
i = Split(i, Chr(29))
'i(0) = [)>0617V0B1001PRID-001-A1S99999
Ignoring the inputbox, this works fine:
Dim s As String, arr
s = "[)><RS>06<GS>17V0B100<GS>1PRID-001-A1<GS>S99999<RS><EOT>"
s = Replace(s, "<RS>", Chr(30))
s = Replace(s, "<GS>", Chr(29))
Debug.Print s '[)>0617V0B1001PRID-001-A1S99999<EOT>
Debug.Print Split(s, Chr(30))(1) '0617V0B1001PRID-001-A1S99999
Debug.Print Split(s, Chr(29))(0) '[)>06
Debug.Print Split(s, Chr(29))(1) '17V0B100
Thanks to Tim for leading me to the correct answer. Below worked for converting key events to text.
Private Sub Text0_KeyPress(KeyAscii As Integer)
Dim i As Integer
i = Me.Text0.SelStart
Select Case KeyAscii
Case 4
Me.Text0.Text = Me.Text0.Text + "<EOT>"
Me.Text0.SelStart = i + 5
Case 29
Me.Text0.Text = Me.Text0.Text + "<GS>"
Me.Text0.SelStart = i + 4
Case 30
Me.Text0.Text = Me.Text0.Text + "<RS>"
Me.Text0.SelStart = i + 4
End Select
End Sub

convert a text to a number

I don't know why this code doesn't work ..i wanna just convert text to number .. It doesn't give me any error but it doesn't work
Public Function ConvertCOMPLEXITYToNumber(ByVal chain As String) As Integer
Select Case chain
Case "1 - Très difficile"
ConvertCOMPLEXITYTToNumber = 1
Case "2 - Difficile"
ConvertCOMPLEXITYTToNumber = 2
Case "3 - Modérée"
ConvertCOMPLEXITYTToNumber = 3
Case "4 - Facile"
ConvertCOMPLEXITYTToNumber = 4
Case Else
ConvertCOMPLEXITYTToNumber = 0
End Select
Exit Function
End Function
That may be because you may have unwanted leading or trailing spaces which fails the comparison. Also you do not need Exit Function at the end of the code. It will exit any ways :)
Try this
Public Function ConvertCOMPLEXITYToNumber(ByVal chain As String) As Integer
Dim Num As Integer
Select Case Trim(chain)
Case "1 - Très difficile": Num = 1
Case "2 - Difficile": Num = 2
Case "3 - Modérée": Num = 3
Case "4 - Facile": Num = 4
Case Else: Num = 0
End Select
ConvertCOMPLEXITYToNumber = Num
End Function
If IsNumeric(Left(Trim(chain),1)) Then
ConvertCOMPLEXITYToNumber = Left(Trim(chain),1)
Else
ConvertCOMPLEXITYToNumber = 0
End If
Here, my approach for you:
Public Function ConvertCOMPLEXITYToNumber(ByVal chain As String) As Integer
'Get the first character
chain = Left(Trim(chain), 1)
'If frist character is numeric
If IsNumeric(chain) Then
'If first number is less than 5, return value
If chain < 5 Then
ConvertCOMPLEXITYToNumber = CInt(chain)
End If
End If
End Function

convert hindi number to word in vb.net

i am trying to convert numbers to word for a hindi invoice .
like - 50001 to पांच हजार एक
Public Shared Function changeToWords(ByVal numb As [String]) As [String]
Dim val As [String] = "", wholeNo As [String] = numb, points As [String] = "", andStr As [String] = "", pointStr As [String] = ""
Dim endStr As [String] = ""
Try
Dim decimalPlace As Integer = numb.IndexOf(".")
If decimalPlace > 0 Then
wholeNo = numb.Substring(0, decimalPlace)
points = numb.Substring(decimalPlace + 1)
If Convert.ToInt32(points) > 0 Then
andStr = "दशाम्लौ"
' just to separate whole numbers from points
pointStr = translateCents(points)
End If
End If
val = [String].Format("{0} {1}{2} {3}", translateWholeNumber(wholeNo).Trim(), andStr, pointStr, endStr)
Catch
End Try
Return val
End Function
Private Shared Function translateWholeNumber(ByVal number As [String]) As [String]
Dim word As String = ""
Try
Dim beginsZero As Boolean = False
'tests for 0XX
Dim isDone As Boolean = False
'test if already translated
Dim dblAmt As Double = (Convert.ToDouble(number))
'if ((dblAmt > 0) && number.StartsWith("0"))
If dblAmt > 0 Then
'test for zero or digit zero in a nuemric
beginsZero = number.StartsWith("0")
Dim numDigits As Integer = number.Length
Dim pos As Integer = 0
'store digit grouping
Dim place As [String] = ""
'digit grouping name:hundres,thousand,etc...
Select Case numDigits
Case 1
'ones' range
word = ones(number)
isDone = True
Exit Select
Case 2
'tens' range
word = tens(number)
isDone = True
Exit Select
Case 3
'hundreds' range
pos = (numDigits Mod 3) + 1
place = " सौ "
Exit Select
'thousands' range
Case 4, 5
pos = (numDigits Mod 4) + 1
place = " हजार "
Exit Select
Case 6, 7
pos = (numDigits Mod 6) + 1
place = " लाख "
Exit Select
'millions' range
Case 8, 9, 10
pos = (numDigits Mod 8) + 1
place = " करोड़ "
Exit Select
Case Else
'add extra case options for anything above Billion...
isDone = True
Exit Select
End Select
If Not isDone Then
'if transalation is not done, continue...(Recursion comes in now!!)
word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos))
'check for trailing zeros
If beginsZero Then
word = " " & word.Trim()
End If
End If
'ignore digit grouping names
If word.Trim().Equals(place.Trim()) Then
word = ""
End If
End If
Catch
End Try
Return word.Trim()
End Function
Private Shared Function tens(ByVal digit As [String]) As [String]
Dim digt As Integer = Convert.ToInt32(digit)
Dim name As [String] = Nothing
Select Case digt
Case 10
name = "दस"
Exit Select
Case 11
name = "ग्यारह"
Exit Select
Case 12
name = "बारह"
Exit Select
Case 13
name = "तेरह"
Exit Select
Case 14
name = "चौदह"
Exit Select
Case 15
name = "पंद्रह"
Exit Select
Case 16
name = "सोलह"
Exit Select
Case 17
name = "सतरह"
Exit Select
Case 18
name = "अट्ठारह"
Exit Select
Case 19
name = "उन्नीस"
Exit Select
Case 20
name = "बीस"
Exit Select
Case 21
name = "इक्कीस"
Exit Select
Case 22
name = "बाईस"
Exit Select
Case 23
name = "तेईस"
Exit Select
Case 24
name = "चौबीस"
Exit Select
Case 25
name = "पच्चीस"
Exit Select
Case 26
name = "छब्बीस"
Exit Select
Case 27
name = "सत्ताईस"
Exit Select
Case 28
name = "अट्ठाईस"
Exit Select
Case 29
name = "उनतीस"
Exit Select
Case 30
name = "तीस"
Exit Select
Case 31
name = "इकतीस"
Exit Select
Case 32
name = "बत्तीस"
Exit Select
Case 33
name = "तैंतीस"
Exit Select
Case 34
name = "चौंतीस"
Exit Select
Case 35
name = "पैंतीस"
Exit Select
Case 36
name = "छ्त्तीस"
Exit Select
Case 37
name = "सैंतीस"
Exit Select
Case 38
name = "अड़तीस"
Exit Select
Case 39
name = "उनतालीस"
Exit Select
Case 40
name = "चालीस"
Exit Select
Case 41
name = "इकतालीस"
Exit Select
Case 42
name = "बयालीस"
Exit Select
Case 43
name = "तैंतालीस"
Exit Select
Case 44
name = "चौंतालीस"
Exit Select
Case 45
name = "पैंतालीस"
Exit Select
Case 46
name = "छियालीस"
Exit Select
Case 47
name = "सैंतालीस"
Exit Select
Case 48
name = "अड़तालीस"
Exit Select
Case 49
name = "उनचास"
Exit Select
Case 50
name = "पचास"
Exit Select
Case 51
name = "इक्याबन"
Exit Select
Case 52
name = "बावन"
Exit Select
Case 53
name = "तिरेपन"
Exit Select
Case 54
name = "चौबन"
Exit Select
Case 55
name = "पचपन"
Exit Select
Case 56
name = "छप्पन"
Exit Select
Case 57
name = "सत्तावन"
Exit Select
Case 58
name = "अट्ठावन"
Exit Select
Case 59
name = "उनसठ"
Exit Select
Case 60
name = "साठ"
Exit Select
Case 61
name = "इकसठ"
Exit Select
Case 62
name = "बासठ"
Exit Select
Case 63
name = "तिरसठ"
Exit Select
Case 64
name = "चौंसठ"
Exit Select
Case 65
name = "पैंसठ"
Exit Select
Case 66
name = "छियासठ"
Exit Select
Case 67
name = "सड़सठ"
Exit Select
Case 68
name = "अड़सठ"
Exit Select
Case 69
name = "उनहत्तर"
Exit Select
Case 70
name = "सत्तर"
Exit Select
Case 71
name = "इकहत्तर"
Exit Select
Case 72
name = "बहत्तर"
Exit Select
Case 73
name = "तिहत्तर"
Exit Select
Case 74
name = "चौहत्तर"
Exit Select
Case 75
name = "पचहत्तर"
Exit Select
Case 76
name = "छिहत्तर"
Exit Select
Case 77
name = "सतहत्तर"
Exit Select
Case 78
name = "अठहत्तर"
Exit Select
Case 79
name = "उनासी"
Exit Select
Case 80
name = "अस्सी"
Exit Select
Case 81
name = "इक्यासी"
Exit Select
Case 82
name = "बयासी"
Exit Select
Case 83
name = "तिरासी"
Exit Select
Case 84
name = "चौरासी"
Exit Select
Case 85
name = "पचासी"
Exit Select
Case 86
name = "छियासी"
Exit Select
Case 87
name = "सतासी"
Exit Select
Case 88
name = "अठासी"
Exit Select
Case 89
name = "नवासी"
Exit Select
Case 90
name = "नब्बे"
Exit Select
Case 91
name = "इक्यानवे"
Exit Select
Case 92
name = "बानवे"
Exit Select
Case 93
name = "तिरानवे"
Exit Select
Case 94
name = "चौरानवे"
Exit Select
Case 95
name = "पचानवे"
Exit Select
Case 96
name = "छियानवे"
Exit Select
Case 97
name = "सत्तानवे"
Exit Select
Case 98
name = "अट्ठानवे"
Exit Select
Case 99
name = "निन्यानवे"
Exit Select
Case Else
If digt > 0 Then
name = (tens(digit.Substring(0, 1) & "0") & " ") + ones(digit.Substring(1))
End If
Exit Select
End Select
Return name
End Function
Private Shared Function ones(ByVal digit As [String]) As [String]
Dim digt As Integer = Convert.ToInt32(digit)
Dim name As [String] = ""
Select Case digt
Case 1
name = "एक"
Exit Select
Case 2
name = "दो"
Exit Select
Case 3
name = "तीन"
Exit Select
Case 4
name = "चार"
Exit Select
Case 5
name = "पांच"
Exit Select
Case 6
name = "छः"
Exit Select
Case 7
name = "सात"
Exit Select
Case 8
name = "आठ"
Exit Select
Case 9
name = "नौ"
Exit Select
End Select
Return name
End Function
Private Shared Function translateCents(ByVal cents As [String]) As [String]
Dim cts As [String] = "", digit As [String] = "", engOne As [String] = ""
For i As Integer = 0 To cents.Length - 1
digit = cents(i).ToString()
If digit.Equals("0") Then
engOne = "शून्य"
Else
engOne = ones(digit)
End If
cts += " " & engOne
Next
Return cts
End Function
i tried the above coe . it is running but when
the number comes like 50001 it gives output पचास हजार सौ एक .
i want to write this as पचास हजार एक .
This modification seems to be working for me:
'if transalation is not done, continue...(Recursion comes in now!!)
If (number.Substring(0, 1) = "0") Then
word = translateWholeNumber(number.Substring(pos))
Else
word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos))
End If
Edit: Doing this breaks output if the original string sent to changeToWords begins with any zeros. To rectify that condition, you can trim leading zeros, before the string is processed:
wholeNo As [String] = numb.TrimStart("0"c)

VB select case not working as expected

I am a total novice with visual basic and teaching myself as I go along. I am building a VB in studio 2008 (I'm obliged to use this version) that logs into a device , transmits log in and password and then transmits commands read from a .txt file using reflections. All of this is working fine. The device executes the command and outputs 1 of 28 possible responses.
I am using select case to evaluate the responses and act accordingly. The device session stops as expected when EXECUTED is seen in the session window, my test data is designed so the first response I get is "EXECUTED", the weird thing is my VB "sees" the EXECUTED message (Case 1) but select case responds as if it has seen FAILED (Case 2), subsequent lines of the test data illicit different cases (5 and 6) but the response is always the next case along. I have tried Case n, case is = n, case "string value" but I get errors.
Here's my code - note that I haven't defined all 28 cases yet but the undefined ones are REM'ed out in my active version. Any ideas or suggestions would be gratefully received!
Option Explicit On
Public Class modCaseSelect
Shared Sub Dev_Responses(ByVal refl)
Dim Result As String
Dim CR = vbCr
Dim Resp As Integer
Dim Dev_Resp(28) As String
Dev_Resp(0) = "RUNNING"
Dev_Resp(1) = "EXECUTED"
Dev_Resp(2) = "FAILED"
Dev_Resp(3) = "SEMANTICS ERROR"
Dev_Resp(4) = "NONEXISTENT"
Dev_Resp(5) = "NOT FOUND"
Dev_Resp(6) = "SPECIAL"
Dev_Resp(7) = "CONFIRM: Y/N"
Dev_Resp(8) = "CONFIRM (Y/N)"
Dev_Resp(9) = "CONFIRM EXECUTION: Y/N"
Dev_Resp(10) = "ALREADY EXECUTED"
Dev_Resp(11) = ""
Dev_Resp(12) = ""
Dev_Resp(13) = ""
Dev_Resp(14) = ""
Dev_Resp(15) = ""
Dev_Resp(16) = ""
Dev_Resp(17) = ""
Dev_Resp(18) = ""
Dev_Resp(19) = ""
Dev_Resp(20) = ""
Dev_Resp(21) = ""
Dev_Resp(23) = ""
Dev_Resp(23) = ""
Dev_Resp(24) = ""
Dev_Resp(25) = ""
Dev_Resp(26) = ""
Dev_Resp(27) = ""
Dev_Resp(28) = "IN PROGRESS"
With refl
Select Case .WaitForStrings(Dev_Resp, "0:4:30") 'checkDev_Resp
Case 0 ' "RUNNING"
Result = Dev_Resp(0)
Resp = MsgBox((Dev_Resp(0) & CR & CR & Continue?"), 17, "Case 0 error")
Case 1 ' "EXECUTED"
Result = Dev_Resp(1)
Resp = MsgBox((Dev_Resp(1) & CR & CR & "Continue?"), 17, "Case 1")
Case 2 ' "FAILED"
Result = Dev_Resp(2)
Resp = MsgBox((Dev_Resp(2) & CR & CR & "Continue?"), 17, "Case 2 error")
Case 3 ' "SEMANTICS ERROR"
Result = Dev_Resp(3)
Resp = MsgBox((Dev_Resp(3) & CR & CR & "Continue?"), 17, "Case 3 error")
Case 4 ' "NONEXISTENT"
Result = Dev_Resp(4)
Resp = MsgBox((Dev_Resp(4) & CR & CR & "Continue?"), 17, "Case 4 error")
Case 5 ' "NOT FOUND"
Result = Dev_Resp(5)
Resp = MsgBox((Dev_Resp(5) & CR & CR & "Continue?"), 17, "Case 5 error")
Case 6 ' "SPECIAL"
Result = Dev_Resp(6)
Resp = MsgBox((Dev_Resp(6) & CR & CR & "Continue?"), 17, "Case 6 error")
Case 7 ' "CONFIRM: Y/N"
Result = Dev_Resp(7)
.Transmit("Y" & CR)
Case 8 ' "CONFIRM (Y/N)"
Result = Dev_Resp(8)
.Transmit("Y" & CR)
Case 9 ' "CONFIRM EXECUTION: Y/N"
Result = Dev_Resp(9)
.Transmit("Y" & CR)
Case 10 ' "ALREADY EXECUTED"
Result = Dev_Resp(10)
Resp = MsgBox((Dev_Resp(10) & CR & CR & "Continue?"), 17, "Case 10 error")
Case 11 ' ""
Result = Dev_Resp(11)
Case 12 ' ""
Result = Dev_Resp(12)
Case 13 ' ""
Result = Dev_Resp(13)
Case 14 ' ""
Result = Dev_Resp(14)
Case 15 ' ""
Result = Dev_Resp(15)
Case 16 ' ""
Result = Dev_Resp(16)
Case 17 ' ""
Result = Dev_Resp(17)
Case 18 ' ""
Result = Dev_Resp(18)
Case 19 ' ""
Result = Dev_Resp(19)
Case 20 ' ""
Result = Dev_Resp(20)
Case 21 ' ""
Result = Dev_Resp(21)
Case 22 ' ""
Result = Dev_Resp(22)
Case 23 ' ""
Result = Dev_Resp(23)
Case 24 ' ""
Result = Dev_Resp(24)
Case 25 ' ""
Result = Dev_Resp(25)
Case 26 ' ""
Result = Dev_Resp(26)
Case 27 ' ""
Result = Dev_Resp(27)
Case 28 ' "IN PROGRESS"
Result = Dev_Resp(28)
Resp = MsgBox((Dev_Resp(28) & CR & CR & "Continue?"), 17, "Case 28 error")
Case Else
End Select
End With
End Sub
End Class
You are missing a double quote " in your first Case. Try changing it to this:
Case 0 ' "RUNNING"
Result = Dev_Resp(0)
Resp = MsgBox((Dev_Resp(0) & CR & CR & "Continue?"), 17, "Case 0 error")
Notice I've added the double quote before "Continue?".
Get rid of the With statement. Create and assign a holder variable and use that with the select statement. Doing so will allow you to see what is actually getting passed into the select statement by setting a stop point in the debugger.
Dim temp_resp as integer = refl.WaitForStrings(Dev_Resp, "0:4:30")
Select Case temp_resp
'the case statements here.
End Select
Reflections WaitForStrings uses a zero-based array parameter, but it returns a 1-based index of strings. Waitforstrings sees array entry zero as the first valid entry so the first select case (Case = 1) corresponds to array entry 0.

Finding Substring of String VB

1.The Following Program will get two inputs from user i.e A & B
2. Than Find the sub string from B.
3. Finally Print the result.
While my code is
Dim a As String
Dim b As String
a = InputBox("Enter First String", a)
b = InputBox("Enter 2nd String", b)
Dim i As Integer
Dim j As Integer = 0
Dim k As Integer = 0
Dim substr As Integer = 0
For i = 0 To a.Length - 1
If a(i) = b(j) Then
j += 1
If b(j) = 0 Then
MsgBox("second string is substring of first one")
substr = 1
Exit For
End If
End If
Next i
For i = 0 To b.Length - 1
If b(i) = a(k) Then
k += 1
If a(k) = 0 Then
MsgBox(" first string is substring of second string")
substr = 1
Exit For
End If
End If
Next i
If substr = 0 Then
MsgBox("no substring present")
End If
End Sub
While compiling it gives following debugging errors.
Line Col
Error 1 Operator '=' is not defined for types 'Char' and 'Integer'. 17 24
Error 2 Operator '=' is not defined for types 'Char' and 'Integer'. 27 24
It is because of these lines:
If b(j) = 0 Then
If a(k) = 0 Then
As a(k) and b(j) are both of the Char data type (think of the string as an array of characters) but you are trying to compare them to an int (0).
If you are looking for a substring and you're using VB.NET you could try using the IndexOf method, for a very naive example:
If a.IndexOf(b) > -1 Then
MsgBox("b is a substring of a")
ElseIf b.IndexOf(a) > -1 Then
MsgBox("a is a substring of b")
Else
MsgBox("No substring found")
End
If you are using VBA, you could also use InStr but I think with this the string is 1-indexed instead of 0-indexed (as they are in VB.NET) so your check may look something like:
If InStr(a,b) > 0 Then
MsgBox("b is a substring of a")
ElseIf InStr(b,a) > 0 Then
MsgBox("a is a substring of b")
Else
MsgBox("No substring found")
End