|
-
May 3rd, 2016, 04:51 AM
#1
Thread Starter
PowerPoster
Take the left part of a math question, and cut off the right par after the = sign.
Hi there! I am working on a math review game for teachers. Basically, they come up with a list of math questions ex: 1+1=2. What I would like to do, is have the program cut off the question and put it in QuestionLBL.caption
In this case would be 1+1, and the answerLBL.caption would be 2. So I am looking for a way to cut off at the equal sign. 
Would anyone know how to do that?
Thanks!
-
May 3rd, 2016, 06:12 AM
#2
Re: Take the left part of a math question, and cut off the right par after the = sign
You can use the InStr function to return the position of the equal sign, then use Left$ to get the leftmost portion, and Mid$ to get the rightmost portion.
For example:
Code:
Public Sub SplitEquation(ByVal p_Equation As String)
Dim l_EqualPos As Long
l_EqualPos = InStr(p_Equation, 1, "=")
If l_EqualPos < 1 Then Err.Raise 5, , "Not an equation!"
Me.questionLBL.Caption = Left$(p_Equation, l_EqualPos)
Me.answerLBL.Caption = Mid$(p_Equation, l_EqualPos + 1)
End Sub
Note the above was written off the top of my head (untested in IDE), so there may be errors. It should point you in the right direction though.
-
May 3rd, 2016, 06:30 AM
#3
Re: Take the left part of a math question, and cut off the right par after the = sign
The Split function could be your friend here.
Code:
Dim strEquation As String
Dim strQuestion As String
Dim strAnswer As String
Dim strParts() As String
strEquation = "1 + 1 = 2"
strParts = Split(strEquation, "=")
strQuestion = Trim(strParts(0))
strAnswer = Trim(strParts(1))
MsgBox "Question: " & strQuestion & vbCrLf & "Answer: " & strAnswer
-
May 3rd, 2016, 06:52 AM
#4
Re: Take the left part of a math question, and cut off the right par after the = sign
Even better! Should remember not to post before my first coffee
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|