Results 1 to 15 of 15

Thread: variable for 'anyword'

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    20

    Question variable for 'anyword'

    I need to dim a variable representing any single word, of indeterminate length, but a single collection of letters. Seems easy enough. Help, anyone?

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,753

    Re: variable for 'anyword'

    It sounds like you want to declare a String variable:
    Code:
    Dim anyword As String
    The code broken down:
    1. Dim - Starts the declaration process
    2. anyword - Specifies the name of the variable
    3. As - Required part of the declaration process
    4. String - Represents the data type


    Edit: String values are represented by double quotes, so if you wanted to assign the variable to some value it would be like this:
    Code:
    Dim anyword As String = "Hello World!"
    
    'Or
    
    Dim anyword As String
    anyword = "Hello World!"
    Last edited by dday9; Feb 2nd, 2015 at 03:23 PM.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    20

    Re: variable for 'anyword'

    Maybe I've been over-thinking it. I'll give it a shot. Thanks.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    20

    Re: variable for 'anyword'

    I can't use it until I assign it a value. That's the catch. How do I assign anyword value of "any single collection of letters"?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    20

    Re: variable for 'anyword'

    This didn't work.

    Code:
    Dim anyword As Array(Of Char)

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: variable for 'anyword'

    Quote Originally Posted by Nena View Post
    I can't use it until I assign it a value. That's the catch. How do I assign anyword value of "any single collection of letters"?
    Here's a way:
    Code:
    Dim anyword As String = String.Empty
    Alternatively you can write "" (without any space) instead of String.Empty.

    BB

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,753

    Re: variable for 'anyword'

    Well a string is a collection of letters, but try declaring a List(Of String):
    Code:
    Dim anyword As List(Of String) = New List(Of String)
    Then to add a value to it, call it's add method:
    Code:
    anyword.Add("foo1")
    anyword.Add("foo2")
    anyword.Add("foo3")
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    20

    Re: variable for 'anyword'

    But it isn't really empty, is it? That seems to be the curb I keep hitting (over and over again).

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: variable for 'anyword'

    Frankly, the whole question doesn't make a whole lot of sense, so everybody is kind of guessing at what you are wanting. You talk about a "single collection of letters". As opposed to what, exactly? Would there be multiple collections of letters? What would that look like?
    My usual boring signature: Nothing

  10. #10
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: variable for 'anyword'

    Quote Originally Posted by Nena View Post
    I need to dim a variable representing any single word, of indeterminate length, but a single collection of letters. Seems easy enough. Help, anyone?
    To 'Dim' a variable that can hold letters with a maximum length of approximately 2 billion letters do this:

    Code:
     Dim anyword As String
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    20

    Re: variable for 'anyword'

    1. door
    2. window
    3.
    5. painting

    Sorry to be vague, but I strive to be as brief as possible. I need to write a program that will 1) identify missing lines (i.e. "4.", from above) and 2) identify numbered lines that have nothing following the number (i.e. "3.). It's a poorly composed inventory for an estate sale. I want to go through the list and insert missing lines ("4. Missing") and information (3. NoDescription). I can format the text for each condition, and I know how to iterate the numbers, but the "no description" or "anyword" is jamming me up. Yawn for you folks. I'm grateful for any direction. At this rate, I could have sifted through these 100 pages by hand.

  12. #12
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    311

    Re: variable for 'anyword'

    I'd agree with dday9 that that is probably what the question is attempting to find...

    But being that programming is very exact and literal, then the question isn't quite right in that the answer is much more complex than a simple variable declaration. The reason why I say this is that the variable is supposed to represent "any single word, of indeterminate length, but a single collection of letters" but a String doesn't limit the variable to a single word nor does it limit it to just a collection of letters. A String is a type of variable that holds a collection of characters, including letters, numbers, and other characters like spaces and punctuation marks. Thus "123!?#$%" is still a valid String but wouldn't satisfy the restrictions of it containing only letters; likewise "Hello World!" is also a valid String but in this case represents 2 words as well as the exclamation mark. So while a String is the perfect choice for a DataType that can handle a single word of only letters, just that single variable declaration wouldn't be able to implement the other rules to ensure that it is only a single word and only of letters.

    This is actually where Properties are a benefit when making complex programs. Properties are essentially variables that are tied to a particular class. You could make a simple Property very similar to declaring any other variable:
    Code:
    Private Class MyClass
        Public Property Anyword As String
    End Class
    
    Dim myInstance As New MyClass
    myInstance.Anyword = "Hello"
    However Properties are more powerful than a simple variable in that they have special methods called Setters and Getters that Set the Property to a value or Get the value that is currently stored, respectively. The power comes in terms of being able to handle other stuff when attempting to Set or Get a value. For example, let's say that you need to store a Username that needs to be at least 5 characters long but cannot exceed 25 characters. You might therefore set up a Property to check for these rules in its Setter:
    Code:
    Private Class MyClass
        Private strUser As String
    
        Public Property Username As String
            Get
                Return strUser
            End Get
            Set(ByVal Value As String)
                If Value.Length < 5 Or Value.Length > 25 Then
                    MsgBox("Username must be between 5 and 25 characters in length.", MsgBoxStyle.Exclamation, "Invalid Username")
                    strUser = ""
                Else
                    strUser = Value
                End If
            End Set
        End Property
    End Class
    
    Dim myA As New MyClass
    myA.Username = "oops" ' This will display an error message and will actually set myA.Username to an empty string ""
    MsgBox("Variable myA contains Username '" & myA.Username & "'") ' Will display: Variable myA contains Username ''
    
    myA.Username = "This Is OK"
    MsgBox("Variable myA contains Username '" & myA.Username & "'") ' Will display: Variable myA contains Username 'This Is OK'

  13. #13
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: variable for 'anyword'

    Maybe you should show us what you DO have. There's no much point in us making suggestions since it still feels like we're just guessing.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    20

    Re: variable for 'anyword'

    Thanks.

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Feb 2015
    Posts
    20

    Re: variable for 'anyword'

    I don't want to trouble you anymore. Thanks for the attention.

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