Results 1 to 11 of 11

Thread: Calculator Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    5

    Calculator Help

    I'm learning VB in my school, and i have some homework this weekend. my problem is i've forgotten the proper prefix for a frame, i thought frm, but thats for the form, so whats a frame?
    Last edited by GW2live; Feb 17th, 2008 at 03:35 PM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Proper Prefix for Frames?

    Welcome to Forums!

    There is no such thing as "proer prefix" - most people would use "fra" but it isn't necessary.
    You can name your control anyhow you wish - just don't keep the default name and try always changing it to something meaningful:

    fraOptions
    MyOptionsContainer
    mainFrame
    MainContainer

    ... and so one ... however you must be cnsistent with your naming conventions.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    5

    Re: Proper Prefix for Frames?

    my teacher insists that we use them, fra seems to be correct. thanks for the help. i may need a little more so ill just post here rather then making a new thread if it comes to that.

  4. #4
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Proper Prefix for Frames?

    I always use fra, some my forms have 10,000 lines of code, when searching for a frame in the Properties combo they are always grouped together
    fraTaxOptions
    fraProfitOptions
    fraPrintOptions and always use Mixed case
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    5

    Re: Proper Prefix for Frames?

    Alright well I need help again. I uploaded what i have (which isnt much) all i've done is porgrammed the done button. But what i have to do is make the frame disabled if the value of either text box is 0. im typing what i wrote but it doesnt work. what i wrote was
    Code:
    fraFunction.Enabled =False if txtNum1.Text = 0
    but it doesnt work, I need to make it only recognise text as integer as well but I forget how, I want to learn I dont want it done for me, so if someone could maybe edit mine upload it then I could see how they did it or just tell me what I need to do.
    Attached Files Attached Files
    Last edited by GW2live; Feb 17th, 2008 at 03:33 PM.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    5

    Re: Calculator Help

    bump

  7. #7
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Calculator Help

    Code:
    Sub numbersOnly(KeyAscii As Integer, txtBox As TextBox)
    On Error GoTo e
        
      If KeyAscii <> 8 And KeyAscii <> 45 And KeyAscii <> 46 And KeyAscii <> 13 Then
      If Chr(KeyAscii) < "0" Or Chr(KeyAscii) > "9" Then
        KeyAscii = 0
        Beep
        End If
    
        End If
    
        If InStr(txtBox, ".") Then 'only allow 1 decimal
        If KeyAscii = 46 Then KeyAscii = 0
        Exit Sub
        End If
    
      If Len(txtBox.Text) > 0 And KeyAscii = 45 Then 'only allow minus sign in leftmost position
         KeyAscii = 0
        End If
      Exit Sub
    e:
       MsgBox "numbersOnly" & err.number & " " & err.Description
    
        End Sub
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    5

    Re: Calculator Help

    woah. that just went clean over my head. im doing basic basic stuff here. that is definatley not the way he shwoed us how to do it. (mind you he didnt show us much) now my brain hurts.

  9. #9
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Calculator Help

    Hi,

    I made this Calculator a few years ago back in 2004.

    Please download the code and have a look to see if iy helps in anyways.

    Thanks
    Attached Files Attached Files
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  10. #10
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Calculator Help

    Quote Originally Posted by GW2live
    woah. that just went clean over my head. im doing basic basic stuff here. that is definatley not the way he shwoed us how to do it. (mind you he didnt show us much) now my brain hurts.
    just call it like this:
    Private Sub text1_KeyPress(KeyAscii As Integer)

    numbersOnly KeyAscii, text1

    Exit Sub
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  11. #11
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculator Help

    In case you haven't realised, the form of the If statement is the other way round to the way you tried
    Code:
    fraFunction.Enabled =False if txtNum1.Text = 0
    should be
    Code:
    If txtNum1.Text = 0 Then fraFunction.Enabled = False
    In general, the If statement syntax is:
    Code:
     
    If <some condition> Then 
        '
        ' Code goes here if <some condition> evaluates to True
        '
    Else
        '
        ' Code goes here if <some condition> evaluates to False
        '
    End If
    The Else clause is optional but the End If is mandatory unless the whole statement is on one line. So
    Code:
    If x <> 0 Then Y = 20
    is valid, as is
    Code:
    If X <> 0 Then
        Y = 20
    End If
    but
    Code:
    If X <> 0 Then
        Y = 20
    is not valid.

    A couple of general tips in case your Teacher doesn't insist on them:

    (a) Always put Option Explicit in the Declarations Section of your Form. It forces you to define all the variables you use and will save you countless hours of debugging.

    (b) Indent your code (eg as I have done with the If / Then / Else / End If above) when you use If / Select Case / Do / For / and any other statements that are executed in "Blocks". IT makes the code easier to read and understand and also it's fairly obvious is you've missed things like End If off a block of code
    eg
    Code:
    If X = 20 Then
    If y=30 Then
    z=4
    Else 
    z=7
    End If
    q=34
    In the above it's not too obvious that there's an End If missing, whereas
    Code:
    If X = 20 Then
        If Y = 30 Then
            z=4
        Else
            z=7
        End If
        q = 34
    It's fairly obvious that there's an End If missing just by looking at the indentation.
    Last edited by Doogle; Feb 18th, 2008 at 02:44 AM.

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