iLogic - Searching String to Find Fraction's Value

iLogic - Searching String to Find Fraction's Value

itteam
Participant Participant
645 Views
1 Reply
Message 1 of 2

iLogic - Searching String to Find Fraction's Value

itteam
Participant
Participant

Good Day, 

 

I'm trying to send a string that contains a fraction in this format: 1 3 / 4". I am trying to have the function split this string into three separate strings so that I may convert the values to double and perform the the necessary operations. 

 

The problem is, I'm trying to trigger where the second half of the fraction is based off of if the slash has been found or not yet. However, when I try to use the following code, it is not setting slashAchieved to True at the necessary point and, as such, stores everything after the whole number into NewStr instead of splitting it between NewStr and NewStr2. Any ideas? Thank you. 

 

Function DetermineGLQtyParam(TempStr As String) As Double
	
	' Set Needed Variables.
	Dim LenStr As Integer = Len(TempStr)
	MessageBox.Show(LenStr)
	Dim i As Integer = 1
	Dim slashAchieved As Boolean = False
	Dim wholeNumberPresent As Boolean = False
	Dim NewStr As String
	Dim NewStr2 As String
	Dim WholeNumber As String = "0"
	
	
	'Iterate through string and establish true number.
	While i < LenStr
		
		' Grab first half of Fraction (or Whole Number, if Present)
		If IsNumeric(Mid(TempStr, i, 1)) And slashAchieved = False Then
			NewStr = NewStr & Mid(TempStr, i, 1)
			MessageBox.Show("Character: " & Mid(TempStr, i, 1) & " found a home in IF 1")
		'If the next character is a space and we haven't reached the slash, and the character after the space is not a slash, assume the current NewStr is a whole number, store it, and reset the NewStr.
		Else If Mid(TempStr, i, 1) = " " And slashAchieved = False And Mid(TempStr, i+1, 1) <> "/" Then
			wholeNumberPresent = True
			WholeNumber = NewStr
			NewStr = ""
			MessageBox.Show("Character: " & Mid(TempStr, i, 1) & " found a home in IF 2")
		'Grab Slash
		Else If Not(IsNumeric(Mid(TempStr, i, 1))) Then
			If Mid(TempStr, i, 1) = "/"
				slashAchived = True
			End If
			MessageBox.Show("Character: " & Mid(TempStr, i, 1) & " found a home in IF 3")
		'Grab Second Half of Fraction
		Else If IsNumeric(Mid(TempStr, i, 1)) And slashAchieved = True Then
			NewStr2 = NewStr & Mid(TempStr, i, 1)
			MessageBox.Show("Character: " & Mid(TempStr, i, 1) & " found a home in IF 4")
		End If		
		
		i = i + 1
		
	End While
	
	Dim GLQTYPARAM As Double
	GLQTYPARAM = ((CDbl(NewStr) / CDbl(NewStr2)) + WholeNumber) * 2.54
	MessageBox.Show("GLQTYPARAM: " & GLQTYPARAM & vbCrLf & "Whole Number: " & WholeNumber & vbCrLF & "New Str 1: " & NewStr & vbCrLF & "New Str 2: " & NewStr2 & vbCrLf & "slashAchieved: " & slashAchieved.ToString)
	Return GLQTYPARAM
	
End Function
0 Likes
Accepted solutions (1)
646 Views
1 Reply
Reply (1)
Message 2 of 2

itteam
Participant
Participant
Accepted solution

Apologies, misspelling on variable used to store slashFound. Please disregard.

0 Likes