Results 1 to 22 of 22

Thread: [RESOLVED] need help!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Location
    Philippines
    Posts
    4

    Resolved [RESOLVED] need help!!!

    hi!!!

    im new here...this vb forum really helps me a lot. I got codes here yesterday that help me passed by thesis defense. thanks to goran...

    However, Im still working out with my new project that was really hard for me because im so busy with other programs assigned to me by my other teachers.

    Can somebody help me please...

    The vb project is about a program that accepts the if-else condition

    for example, you enter the if-else condition on a textbox (eg. x = y or x+y = z) when you click the test button a msg box will appear telling you that the condition is accepted or invalid. Thats it!

    Guys, I really need your help...Thanks in advance!

  2. #2
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: need help!!!

    Well.... maybe you will need some stuff to make the code better and error-proof.
    Hope i understood what you wanted, if not just tell me.

    VB Code:
    1. Private Sub cmdTest_Click()
    2. Dim X
    3. Dim Y
    4. Dim equalChar As Integer
    5.  
    6. equalChar = InStr(1, Text1, "=")
    7. If equalChar = 0 Then
    8.    MsgBox "No '=' was found on your entry." '
    9.    Exit Sub
    10. End If
    11.  
    12. X = Left(Text1, equalChar - 1)
    13. Y = Right(Text1, Len(Text1) - equalChar)
    14.  
    15. If Y = X Then
    16.    MsgBox "TRUE"
    17. Else
    18.    MsgBox "FALSE"
    19. End If
    20. End Sub

  3. #3
    Addicted Member o0yuna0o's Avatar
    Join Date
    Mar 2006
    Posts
    172

    Re: need help!!!

    Im also from philippines... from what school are you... i dont know if i still have my case studies on my pc... as i remember i have a case study like yours...

    is your input is from 1 textbox only?

    me i used split() function for validating if it is invalid or not

  4. #4
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    Re: need help!!!

    <-------- is also a filipino... welll, some reunion huh?

    sori but i dont really understand ur problem... have u tried to do some coding with this?
    remember that this forums doesnt give you the codes...it helps you solve your roblem with them so you've got to start somewhere b4 we can help u...
    WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...

  5. #5
    Addicted Member o0yuna0o's Avatar
    Join Date
    Mar 2006
    Posts
    172

    Re: need help!!!

    i will not actually giving her my case study... i just want to know which school she came from...

    We might have same school...

    and another thing... i can't give my case study to her because mine is in c language not in vb

    Last edited by o0yuna0o; Mar 15th, 2006 at 11:56 PM.

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Location
    Philippines
    Posts
    4

    Re: need help!!!

    thanks guys!!!

    Kanbei's code was somewhat similar with my codes but my professor said it still need improvement. The program should allow the user to enter an if condition in 1 textbox only. The program should accept recursive or nested condition like for example:
    (x+y=o) || (x/y=p) or it can also accept < > symbols like (x>y) && (y=z).

    I really need this by tomorrow...so guys im begging you..please help me!

    ...by the way, im also a filipino.

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: need help!!!

    Pinoy din ako...

    Ano ba problema?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8
    Addicted Member o0yuna0o's Avatar
    Join Date
    Mar 2006
    Posts
    172

    Re: need help!!!

    am i allowed to speak filipino language here... so i can explain it well to glyz???

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: need help!!!

    Sure, but we'd prefer it if you also provided an English translation to assist non-Filipino speakers who may have the same problem

  10. #10
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: need help!!!

    As stated earlier you could use the Instr function for such validation but I am not sure if you could achieve 100% fool-proof validation with such cases...

    I haven't done Regulare Expressions but it may be of help altogether...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  11. #11
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: need help!!!

    1st: this guy seems to be in a problem.... use somewhere else as chat room!

    i knew my code wasnt perfect, just wanted to see if the idea was what you wanted:
    You should in fact use InStr (only way i see)
    This is what i recommend (cant write the whole code right now... but tell me if you have problems and maybe later).

    1st make sure there is a equal sign BUT NO MORE:
    VB Code:
    1. Dim X 'Will be the first part of the math
    2. Dim Y 'Will be the second part of the math
    3. Dim equalChar As Integer 'Position of the equal
    4.  
    5. equalChar = InStr(1, Text1, "=")
    6. If equalChar = 0 Then 'If not equal sign found, exit
    7.    MsgBox "No '=' was found on your entry." '
    8.    Exit Sub
    9. Elseif InStr(1, Text1, "=") > 0 then 'If more than 1 equal sign found, exit
    10.    MsgBox "Please don't enter more than one '=' sign." '
    11.    Exit Sub
    12. End If
    13.  
    14. X = Left(Text1, equalChar - 1)
    15. Y = Right(Text1, Len(Text1) - equalChar)
    16.  
    17. 'Right now you have both parts each one in one variable, maybe you would like yo make sure also some stuff...
    18. 'like no letters are on them or chars like & or #, since i dont know 100% cant do that.
    19. 'Also i dont know if there is a chance than more than 1 operation will be done in each, like 7*1+12=33/3*7+4,
    20.  
    21. ' but i think you can do this using the InStr to find the +,-,*,/,etc. and then useing a "select case"... ill try a few stuff and post again since im not sure how to do it 100%.

    BTW.... why do you need this? cause its much easier if you 4 example type everything like a calculator, with one button for "+" another for "*", etc.
    Last edited by Kanbei; Mar 16th, 2006 at 10:19 AM.

  12. #12

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Location
    Philippines
    Posts
    4

    Re: need help!!!

    Tnx a lot!!!

    I need this because its my requirement to be able to pass the final exam.
    I dont think its the same as a calculator, to be more specific...it is a Turbo C if condition syntax checker.

  13. #13
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: need help!!!

    ok. so tell me if you have any problem with the rest of the code and if you want me to write it for you then plz tell me EXACTLY what can and cannot be entered.
    Good Luck!

  14. #14
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Validating Algebraic Equations

    here's a solution:

    VB Code:
    1. Private Function Validate(ByVal sEquation As String, _
    2.                           ByRef sError As String, _
    3.                           Optional ByVal IsTopLevel As Boolean = True) As Boolean
    4.  
    5.     Const sComparison As String = " < > = || && & " ' Add Valid Comparison operators here
    6.     Const sOperators As String = " + - * /  ^ " ' Add valid Calculation operators here
    7.    
    8.     Const sIndicator As String = "?" ' A character which doesn't clash with anything else
    9.     Const sAlgebra As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    10.     Const sInteger As String = "0123456789."
    11.  
    12.     Dim N As Integer, lPos As Integer
    13.     Dim arrComp() As String, sChar As String
    14.     Dim bValue As Boolean
    15.    
    16.     ' Check the equation isn't ""
    17.     If LenB(Trim$(sEquation)) = 0 Then
    18.         If Not bTopLevel Then sError = "Empty Paretheses"
    19.         Exit Function
    20.     End If
    21.    
    22.     'Check For Brackets
    23.     Do While InStr(sEquation, "(") Or InStr(sEquation, ")")
    24.         For N = 1 To Len(sEquation)
    25.             sChar = Mid$(sEquation, N, 1)
    26.             If sChar = "(" Then
    27.                 lPos = N
    28.             ElseIf sChar = ")" Then
    29.                 If lPos Then
    30.                     ' Bracket Pair Found - Validate it
    31.                     If Not Validate(Mid$(sEquation, lPos + 1, N - lPos - 1), sError, False) Then Exit Function
    32.                     sEquation = Left$(sEquation, lPos - 1) & sIndicator & Mid$(sEquation, N + 1)
    33.                     lPos = 0
    34.                     Exit For
    35.                 Else
    36.                     sError = "Missing Parentheses"
    37.                     Exit Function
    38.                 End If
    39.             End If
    40.         Next N
    41.         If lPos Then
    42.             sError = "Missing Parentheses"
    43.             Exit Function
    44.         End If
    45.     Loop
    46.    
    47.     ' Check Simple Equation Conditions
    48.     ' Must go value, operator, value, operator,..., value.
    49.     For N = 1 To Len(sEquation)
    50.         If bValue Then
    51.             ' This must be an comparison or calculation operator
    52.             sChar = Mid$(sEquation, N, 2)
    53.             If Left$(sChar, 1) = " " Then
    54.                 ' Do Nothing
    55.             ElseIf InStr(sComparison, " " & sChar & " ") Or InStr(sOperators, " " & sChar & " ") Then
    56.                 bValue = Not bValue
    57.                 N = N + 1
    58.             ElseIf InStr(sComparison, " " & Left$(sChar, 1) & " ") Or InStr(sOperators, " " & Left$(sChar, 1) & " ") Then
    59.                 bValue = Not bValue
    60.             Else
    61.                 Exit For
    62.             End If
    63.         Else
    64.             ' This must be a value
    65.             sChar = Mid$(sEquation, N, 1)
    66.             If sChar = " " Then
    67.                 ' Do Nothing
    68.             ElseIf InStr(sAlgebra, UCase$(sChar)) Then
    69.                 Do While InStr(sAlgebra, UCase$(Mid$(sEquation, N + 1, 1)))
    70.                     N = N + 1
    71.                     If LenB(Mid$(sEquation, N + 1, 1)) = 0 Then Exit Do
    72.                  Loop
    73.                 bValue = Not bValue
    74.             ElseIf InStr(sInteger, sChar) Then
    75.                 Do While InStr(sInteger, UCase$(Mid$(sEquation, N + 1, 1)))
    76.                     N = N + 1
    77.                     If LenB(Mid$(sEquation, N + 1, 1)) = 0 Then Exit Do
    78.                 Loop
    79.                 bValue = Not bValue
    80.             ElseIf sChar = sIndicator Then
    81.                 bValue = Not bValue
    82.             Else
    83.                 Exit For
    84.             End If
    85.         End If
    86.     Next N
    87.     If Not N > Len(sEquation) Or Not bValue Then
    88.         sError = "Missing or Invalid " & IIf(bValue, "Operator", "Value")
    89.         Exit Function
    90.     End If
    91.    
    92.     ' Check whether main equation is a comparison
    93.     If IsTopLevel Then
    94.         arrComp = Split(sComparison, " ")
    95.         For N = 1 To UBound(arrComp) - 1
    96.             If InStr(sEquation, arrComp(N)) Then Exit For
    97.         Next N
    98.         If N > UBound(arrComp) - 1 Then
    99.             sError = "No Comparison Operator in Top-Level Equation"
    100.             Exit Function
    101.         End If
    102.     End If
    103.  
    104.     Validate = True
    105. End Function
    it validates simple equations (such as x = y + 5) by checking they go: value, operator, value, operator, value and uses recursion to check all brackets. It also returns the nature of any error encountered.

    The Function accepts an Equation and a Buffer string with which to return the error to. The function returns True if the equation is valid. False if it's not.

    say we have (x / 100) = ((y && q) || (F + K)) which would be called:
    VB Code:
    1. MsgBox Validate("(x / 100) = ((y && q) || (F + K))", sErr)
    the code above does:
    Code:
    Validate (x / 100) = ((y && q) || (F + K))
        Looks for bracket pair: Finds (x / 100)
        Validate x / 100
            Looks for bracket pair: none
            Checks equation order: correct
        Returned: True
        Replaces (x / 100) with ?
    Validate ? = ((y && q) || (F + K))
        Looks for bracket pair: Finds (y && q)
        Validate y && q
            Looks for bracket pair: none
            Checks equation order: correct
        Returned: True
        Replaces (y && q) with ?
    Validate ? = (?|| (F + K))    
        Looks for bracket pair: Finds (F + K)  
        Validate F + K
            Looks for bracket pair: none
            Checks equation order: correct
        Returned: True
        Replaces (F + K) with ?
    Validate ? = (? || ?)  
        Looks for bracket pair: Finds (? || ?)
        Validate ? || ?  
            Looks for bracket pair: none
            Checks equation order: correct
        Returned: True
        Replaces (? || ?) with ?
    Validate ? = ?
        Looks for bracket pair: none
        Checks equation order: correct
        Checks Top Level Equation has comparison operator: True
    Returned: True
    Here is some example variations and outcomes:
    VB Code:
    1. Dim sTemp As String, sText As String, sEq As String, iPos As Integer
    2.     Randomize
    3.    
    4.     sEq = "(x / 100) = ((y && q) || (F + K))"
    5.     For N = 0 To 10
    6.         Do
    7.             iPos = (Len(sEq) - 1) * Rnd + 1
    8.         Loop While Mid$(sEq, iPos, 1) = " "
    9.         sText = Left$(sEq, iPos - 1) & " " & Mid$(sEq, iPos + 1)
    10.         Debug.Print sText & " : " & IIf(Validate(sText, sTemp), True, sTemp)
    11.         sTemp = vbNullString
    12.     Next N
    Code:
    Results
    -------
    (x / 100) = ((y && q) || (F   K)) : Missing Operator
    (  / 100) = ((y && q) || (F + K)) : Missing Value
    (x / 1 0) = ((y && q) || (F + K)) : Missing Operator
    (x / 100) = ((y && q) || (F   K)) : Missing Operator
    (x / 100)   ((y && q) || (F + K)) : Missing Operator
    (x / 100) = ((y && q) ||  F + K)) : Missing Parentheses
    (x / 100) = ((y && q) || (  + K)) : Missing Value
    (x / 10 ) = ((y && q) || (F + K)) : True
    (x / 100) = ((y && q) || (F + K)  : Missing Parentheses
    (x / 100) = ((y && q) || (F + K ) : Missing Parentheses
    (x / 100) = ((y &  q) || (F + K)) : True
    An equation like (X + Y) / (N + M) would return false because it contains no comparison operator (=, >, etc.) in the top-level equation. To remove this check simply call the function like so:
    VB Code:
    1. MsgBox Validate("(X + Y) / (N + M)", sErr, False)

  15. #15
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: need help!!!

    sorry: bush, what is the " || "???

  16. #16
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: need help!!!

    I don't know!

    It's just a random bit of syntax. I've put it as a comparison operator, but it might not be.

    There may well be errors with the code, so let me know if you see any

  17. #17
    Addicted Member o0yuna0o's Avatar
    Join Date
    Mar 2006
    Posts
    172

    Re: need help!!!

    || - (or) operator in c lang

  18. #18
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: need help!!!

    Logical Or, to be more precise. In C and C-based languages.

  19. #19
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: need help!!!

    Aghh, suddenly this is a discussion about C syntax. Get me out of here

  20. #20

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Location
    Philippines
    Posts
    4

    Re: need help!!!

    bush i will try it.If I encounter some error I'll just ask u about it...thats exactly I was lookin for, its somewhat the same as if condition syntax checker. Tnx a lot..

    Kanbei I already try the code but It still have an error...however I wana thnk u for sharing it.I learn something from it.

    oOYunaOo tnx sa email mo...I appreciate it.

    Tnx guys!!

  21. #21
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: need help!!!

    If your questions been answered you should mark this thread resolved by using the 'Thread Tools' at the top of thread

  22. #22
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: need help!!!

    For what it's worth, I've now updated post #15 so that it also returns the reason that the equation has not been validated - Missing Parentheses, Missing Value etc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width