6 Replies - 653 Views - Last Post: 30 January 2013 - 04:07 PM Rate Topic: -----

#1 MrWheels  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-January 13

Array structure and text boxes

Posted 30 January 2013 - 02:50 PM

Hello,
I am brand new to Visual Basic. I have an assignment where I have to create a project that will allow a user to look up a country by its 2 letter abbreviation. The user will have the
options to Look up the Abbreviation or Look up the Country Name. In the event that a match cannot be found for the input, display an appropriate error message. Within this project I have to create a structure of country name and abbreviation and an array of structures. This is what I have so far:

Public Class Form1

    Structure CountryName
        Dim NameString() As String
    End Structure

    Private Country As CountryName
    Private NameString(,) As String = {{AQ, BS, CA, EE, FR, IE, JP, MX, NL}, {Antarctica, Bahamas, Canada, Estonia, France,
                                                                              Ireland, Japan, Mexico, Netherlands}}

Private Sub FindButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindButton.Click
        'Find the correct match for user input and display in.

        Dim FullNameString, AbbNameString As String
        'Establish the number of elements in the array.

        ReDim Country.NameString(9)
        'Convert input group number to a subscript.

        Try
            FullNameString = FullNameTextBox.Text

        Catch ex As Exception

        End Try

    End Sub
End Class


Obviously I'm not even close to being done. I'm have trouble getting the array, structure and variables before the Even Procedure to work (my abbreviations and full names become underlined with "'name of country' is not declared. It may be inaccessible due to its protection level." Any help with explanations on how to get everything running would be greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Array structure and text boxes

#2 CodingSup3rnatur@l-360  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 982
  • View blog
  • Posts: 969
  • Joined: 30-September 10

Re: Array structure and text boxes

Posted 30 January 2013 - 03:15 PM

Hi,

The first problem I see is with your array, NameString. It is an array of strings, and string literals in VB.NET are enclosed in double quotes, so each element in that array needs to be enclosed in double quotes so they are recognized as string literals. That should solve those errors you are getting accessibility levels.

Having said that, I would imagine that your CountryName structure should contain both the full country name AND the corresponding abbreviation. Then, you need an array of CountryName structures, which you can then search. The idea of a structure is to group logically related values and/or behaviors.

This post has been edited by CodingSup3rnatur@l-360: 30 January 2013 - 03:24 PM

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,599
  • Joined: 12-December 12

Re: Array structure and text boxes

Posted 30 January 2013 - 03:16 PM

Quote

I have to create a structure of country name and abbreviation

You haven't done this: your Structure has only the country name, and you have declared it as an array of strings.

Structure Country
    Dim CountryName As String
    Dim CountryAbbr As String
End Structure

Then you can create an array of these:
Dim Countries() As Country 'etc..

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,599
  • Joined: 12-December 12

Re: Array structure and text boxes

Posted 30 January 2013 - 03:22 PM

You could skip the repetition of the word Country without causing any conflict:

Structure Country
    Dim Name As String
    Dim Abbreviation As String
End Structure

Was This Post Helpful? 0
  • +
  • -

#5 MrWheels  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-January 13

Re: Array structure and text boxes

Posted 30 January 2013 - 03:31 PM

View PostCodingSup3rnatur@l-360, on 30 January 2013 - 03:15 PM, said:

Hi,

The first problem I see is with your array, NameString. It is an array of strings, and string literals in VB.NET are enclosed in double quotes, so each element in that array needs to be enclosed in double quotes so they are recognized as string literals. That should solve those errors you are getting accessibility levels.

Having said that, I would imagine that your CountryName structure should contain both the full country name AND the corresponding abbreviation. Then, you need an array of CountryName structures, which you can then search. The idea of a structure is to group logically related values and/or behaviors.


I added the quotes to the NameString() to make them literal. I also added the Dim AbbreviatedNameString() to the CountryName structure.

I know this is a dumb question but I'm unsure how to check the two text boxes for the correct information. I've only worked with list/combo boxes to this point so I'm not sure how the process would look to check the user's input in the text box. Once I see how to check for Canada for instance, I'll know how to do the rest.

Thanks
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,599
  • Joined: 12-December 12

Re: Array structure and text boxes

Posted 30 January 2013 - 03:56 PM

Following my previous example, one way to do this is:

        Dim Countries() As Country = {New Country With {.Name = "France", .Abbreviation = "FR"}} ' etc..

        Dim sCountry As String = "France"   'get this text from TextBox.Text

        For Each item As Country In Countries
            If sCountry = item.Name Then
                'found France in Array!
            End If
        Next

Please study this code - you'll need to anyway, before you can adapt it.

This post has been edited by andrewsw: 30 January 2013 - 03:57 PM

Was This Post Helpful? 0
  • +
  • -

#7 demausdauth  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 174
  • View blog
  • Posts: 629
  • Joined: 03-February 10

Re: Array structure and text boxes

Posted 30 January 2013 - 04:07 PM

Pseudo code it out.
User Input
1. Check for null or empty entry
   A. Is valid input?
      a. yes then continue
      b. no
         i. Display error message
         ii. do not continue processing
2. Process Input

Process Input
1. Determine Abbr vs Full Name (Length?)
   A. Abbr = true
      a. Loop through array of countries (For .. Next?)
      b. Does it match?
         i. yes then matchfound = true
         ii. no then continue loop
   B. Full name = true
      a. Loop through array of countries
      b. Does it match?
         i. yes then matchfound = true
         ii. no then continue loop
2. Is matchfound = true?
   A. Yes
      a. Display abbr or fullname or both
   B. No
      a. Display error message



Once you understand the steps (pseudo code) then you can start applying code.
Pseudo code will also help you to identify parts that can be factored out to separate methods or functions.

This post has been edited by demausdauth: 30 January 2013 - 04:09 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1