Results 1 to 7 of 7

Thread: [RESOLVED] Quick Question from a n00b

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    6

    Resolved [RESOLVED] Quick Question from a n00b

    I am just learning and I found that I should be Declaring my variables as strings or integers from the start. I learned that I can use an * number to determin length.

    Example: Dim yourName as String * 10

    But if I try and do this to an integer it doesn't like it (Dim yourAge as Integer * 2)

    So, does this mean I have to declare it as a string then reference it later using the val() or is there a different way to define allowed integer length?

  2. #2

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Quick Question from a n00b

    Numeric data types like Integer do not have a length, what they have is a minimum and maximum value based on the data type.

    For example, Integer can store whole numbers from -32,768 to 32,767
    Long (long integer) can store whole numbers from -2,147,483,648 to 2,147,483,647

    There are various options for storing numbers with decimal places, such as Single, Double, and Currency.

    You can find info about all of this in VB's help, particularly if you search (by title) for "Data Type Summary".

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    6

    Re: Quick Question from a n00b

    So my thought was correct, if I want to limit the user on how many numbers to put in I need to collect them as a string, that has a length of 2 and then call it as a val() later.

  5. #5
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Quick Question from a n00b

    There are many ways to limit what a user inputs. You can write conditions using If - Then blocks if you wish. For TextBoxes you can set its MaxLength property. The TextBox won't accept chrs exceeding MaxLength.

    Code:
    Text1.MaxLength = 8        ' TextBox limit is 8 chars, including spaces
    I could be wrong but I think you're not quite grasping what Dim means. It will not restrict what a user tries to input. Instead, you will throw an error if a data is entered that does not agree with its declaration type.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  6. #6
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Quick Question from a n00b

    Here's another example: ...
    Use a Textbox and a Commandbutton for testing....
    Code:
    Private Sub Command1_Click()  '~~~> On clicking the commandbutton named 'Command1'
    
      If Val(Text1.Text) <= 0 Or Val(Text1.Text) >= 10 Then         '~~~> Check the user's entry in textbox named 'Text1'
        MsgBox "No...! You have to enter number within the range of 1 to 9"  '~~~> If it is not in the required range, display a message
        Exit Sub  '~~~> Prevent the rest of the codes from being executed
      End If
      
      '~~~ If the checking is a success, then the rest of the codes will be executed
      MsgBox "Good..! You have entered a value in the range of 1 to 9"
      
    End Sub

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    6

    Re: Quick Question from a n00b

    Thanks, that makes more since now.

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