VB 6 Code Project . . .student help needed.

Status
Not open for further replies.

Freeman

Ars Legatus Legionis
14,960
OK, I thought taking a Beginner VB class couldn't be bad. So far its been ok. I am currently getting my butt kicked by a simple take home assignment on constructing and using arrays.

Software: Visual Basic 6 Working Model Edition - NO HELP many features are stripped out / greyed out / disabled.
Text: Programming in VB 6.0 by: J.C. Bradley & A.C. Millspaugh

Project is to set up an Array of seven properties, sort through the array and cull qualified properties to a Text Box. The data is a fixed list of properties: their Address, Price, and defined Area.
The upper portion of the Prog Window uses two Option Buttons for selecting one of two Areas, a Combo Box for selecting and loading which of three defined price ranges, and a Command Button to execute the "cmd_Click()" sort loop through the arrays of Price, Area, and Addresses, using "Case Select" and then list the qualified properties to a Text Box in the lower portion of the form.

I have the Form, as well as a nice Splash screen, but the Dim and Array portion of this is kicking my butt up and down the street.

My problem is primarily in Array / Form Load, and Dim area. Ya, I know - that's everything. : ) At least, right now it is.

Any help on methodology for defining address, price, and area, and assembling this with syntax into array construction would be appreciated and welcome.

I have already invested a quite a fair amount of time wandering aimlessly through the woods, after dark, with a blindfold, trying to get this done.

Thanks & cheers, Freeman
 

Freeman

Ars Legatus Legionis
14,960
Here is my code - so far - in all its glorious/blissful ingnorance:


Option Explicit

Dim mcurPrice(0 To 7, 0 To 0) As Currency
Dim mstrProperty(0 To 7, 1 To 2) As String



Private Sub Form_Load()
' Load Array of Properties
' Column 1 - Price Range
mcurPrice(0, 0) = "48000"
mcurPrice(1, 0) = "160000"
mcurPrice(2, 0) = "148000"
mcurPrice(3, 0) = "92000"
mcurPrice(4, 0) = "155000"
mcurPrice(5, 0) = "129000"
mcurPrice(6, 0) = "58000"
mcurPrice(7, 0) = "114000"

' Column 2 - OptArea
mstrProperty(0, 1) = "Weed"
mstrProperty(1, 1) = "Shasta"
mstrProperty(2, 1) = "Shasta"
mstrProperty(3, 1) = "Weed"
mstrProperty(4, 1) = "Weed"
mstrProperty(5, 1) = "Shasta"
mstrProperty(6, 1) = "Weed"
mstrProperty(7, 1) = "Weed"

'Column 3 - Address
mstrProperty(0, 2) = "123 Walnut Street, Weed, CA"
mstrProperty(1, 2) = "234 East Alma, Mt. Shasta, CA"
mstrProperty(2, 2) = "444 Ream Ave, Mt. Shasta, CA"
mstrProperty(3, 2) = "334 Main Street, Weed, CA"
mstrProperty(4, 2) = "433 Palmer Street, Weed, CA"
mstrProperty(5, 2) = "323 West Jesse, Mt. Shasta, CA"
mstrProperty(6, 2) = "564 Liberty, Weed, CA"
mstrProperty(7, 2) = "343 College Ave, Weed, CA"

End Sub

Private Sub cboPriceRange_Change()
ClearlstProperties
' Load combo box PriceRange
Select Case cboPriceRange.ListIndex

Case "< $ 75,000"
mstrWeed.AddItem "123 Walnut Street, Weed, CA"
mstrWeed.AddItem "564 Liberty, Weed, CA"

Case "< $ 100,000"
mstrWeed.AddItem "123 Walnut Street, Weed, CA"
mstrWeed.AddItem "564 Liberty, Weed, CA"
mstrWeed.AddItem "334 Main Street, Weed, CA"

Case "> $ 100,000"
mstrWeed.AddItem "343 College Ave, Weed, CA"
mstrShasta.AddItem "323 West Jesse, Mt. Shasta, CA"
mstrShasta.AddItem "444 Ream Ave, Mt. Shasta, CA"
mstrShasta.AddItem "433 Palmer Street, Weed, CA"
mstrShasta.AddItem "234 East Alma, Mt. Shasta, CA"

End Select

End Sub


Private Sub cmdFind_Click()

' Find and Load Qualified Properties into list box
' Case statement using selected price range from combo box
intRow = 0
Select Case cboPriceRange.List(cboPriceRange.ListIndex)
Case "<$75,000"
Do Until intRow > 7
If optWeed.Value = True Then
If mstrProperty(intRow, 1) = 1 Then
If Val(mstrProperty(intRow, 2)) < 75000 Then
stProperties.AddItem mstrProperty(intRow, 0)
End If
End If
Else
If mstrProperty(intRow, 1) = 2 Then
If Val(mstrProperty(intRow, 2)) < 75000 Then
lstProperties.AddItem mstrProperty(intRow, 0)
End If
End If
End If
intRow = intRow + 1
Loop

End Sub

Again, thanks to any and all help.

Freeman

sorry about lack of indent formatting - Doh!
 

Alask

Ars Scholae Palatinae
725
Aha the wonderful world of VB..

The way I'd do it would be to define a type to hold the data. Make life a little easier if you ask me..

Something along the lines of

Private Type PROPERTY_DATA
Price as Currency
Property as String
Address as string
End Type

Dim MyPropertyArray(7) as PROPERTY_DATA

'* then load the array using for each lot of data
With MyPropertyArray(0)
.Price = 48000
.Property = "Weed"
.Address = "123 Walnut Street, Weed, CA"
End With

' Then when the combo box with the price range in alters use a
' loop of some sort to loop through the array checking if the
' price is in the right range.
 

Aeirould

Ars Tribunus Angusticlavius
7,535
Subscriptor
OK, there's a lot of misunderstood concepts here. This isn't a flame, it's just a statement of fact. I hope to clear up the misunderstandings.

Oh, leave Type alone for now. It may be the best way, but it's not what you were assigned to do.

First misunderstood concept: " as a variable delimeter.
You've defined mcurPrice as a Currency array and then try to stuff strings into it. What " does is indicate that the value within the " " pair is a String datatype, it is not a borderpost for all expressions.

So,
mcurPrice(0,0) = 48000

and so on.

You have the same problem (using a " as delimeter) on your Case statement.

Second misunderstood concept: Comparisons

Select Case cboPriceRange.ListIndex

Case < 75000

would be correct. You put the comparitive in " " literals. What your code is trying to do is take the value of cboPriceRange.ListIndex and see if it is a String with the value of "< $ 75,000"

Third misunderstood concept: Numeric values

There are many numeric datatypes in VB. Integer, Long, Currency, etc. None of these should be entered in a "formatted" manner. Whenever you want to treat a number as a number and not as a series of characters, you need to just enter the number without formatting characters.

Thus, 75000. Not $75000. Not 75,000. All of those other characters have other meanings to VB.

Last misunderstood concept: Array ranges

You explicitly define the mstrProperty() array to use indices of 0 to 7 on the first index and 1 to 2 on the second (for whatever reason), yet then in your Find routine you attempt to access a value with the second index of 0 - an index that, by your definition, does not exist.

--------------------------

This is new to you and a lot of the concepts most of us, myself included, take for granted are new to you as well. You would do well, however, to read and re-read whatever chapter in your book discusses datatypes, operators and variable formats.
 

Freeman

Ars Legatus Legionis
14,960
Aeirould,

Thank you very much! You da man. Every piece of info helps. Yes, while I was aware I was committing blatant errors of mixed delimeters and types, I did not know "what was what". I have been wandering around - near home plate - knowing I am not in the base line - but not knowing how to go about defining the base line to find home plate. When the knowledge index is so low you don't know what you don't know - boot strapping can be tough.

I have been working this code over and have at this point at least achieved some degree of functionality out of my mess. (no where near finished)

Tenacity is your friend. It just takes a long time to re-invent the wheel. :)
 
Status
Not open for further replies.