Question

Very new to programming and I'm stuck. The code is not 100% finished but should still work. I'm having a problem with using an if statement that equals a variable with words. I just added the quotes and its hanging out that but before I added the quotes it said that if the case was selected then all the If statements were true and added 1 to each of them. Below is what I have. Also just a side question unrelated to this how do I add a variable result to the middle of a sentence? I have only been able to add them to the beginning or end.

(program starts)

WesternMarried=0
WesternSingle=0
WesternDivorced=0
WesternSeperated=0
EasternMarried=0
EasternSingle=0
EasternDivorced=0
EasternSeperated=0
SouthernMarried=0
SouthernSingle=0
SouthernDivorced=0
SouthernSeperated=0
MidwesternMarried=0
MidwesternSingle=0
MidwesternDivorced=0
MidwesternSeperated=0
Print "Which state is subject 1 from?"
Input State1
Print "What is the relationship status of Subject1?"
Input Relation1
Select Case State1
Case CA
    Print "You are from the western region"
    If (Relation1 = "Married") then
    WesternMarried = WesternMarried + 1
    End If
    If (Relation1 = "Single") then
    WesternSingle = WesternSingle + 1
    End If
    If (Relation1 = "Divorced") then
    WesternDivorced = WesternDivorced + 1
    End If
    If (Relation1 = "Seperated") then
    WesternSeperated = WesternSeperated + 1
    End If
Case Else
    Print "You might be from the midwestern states"
    If (Relation1 = "Married") then
    MidwesternMarried = MidwesternMarried + 1
    End If
    If (Relation1 = "Single") then
    MidwesternSingle = MidwesternSingle + 1
    End If
    If (Relation1 = "Divorced") then
    MidwesternDivorced = MidwesternDivorced + 1
    End If
    If (Relation1 = "Seperated") then
    MidwesternSeperated = MidwesternSeperated + 1
    End If
End Select
Print "The number of people married in the midwestern states is " ; MidwesternMarried
Print "The number of people single in the midwestern states is " ; MidwesternSingle
Print "The number of people divorced in the midwestern states is " ; MidwesternDivorced
Print "The number of people separated in the Western states is " ; MidwesternSeperated
Print "The number of people married in the Western states is " ; WesternMarried
Print "The number of people single in the Western states is " ; WesternSingle
Print "The number of people divorced in the Western states is " ; WesternDivorced
Print "The number of people separated in the Western states is " ; WesternSeperated
End
Was it helpful?

Solution

Perhaps this is a better way to do it. If you don't have quotations around your strings then it will think that it is a variable. Also, you need to have the $ after your variables, this signifies that it is a string.

WesternMarried=0
WesternSingle=0
WesternDivorced=0
WesternSeperated=0
EasternMarried=0
EasternSingle=0
EasternDivorced=0
EasternSeperated=0
SouthernMarried=0
SouthernSingle=0
SouthernDivorced=0
SouthernSeperated=0
MidwesternMarried=0
MidwesternSingle=0
MidwesternDivorced=0
MidwesternSeperated=0
Print "Which state is subject 1 from?"
Input State1$
Print "What is the relationship status of Subject1?"
Input Relation1$
Select Case State1
Case "CA"
    Print "You are from the western region"
    If (Relation1$ = "Married") then
       WesternMarried = WesternMarried + 1
    End If
    If (Relation1$ = "Single") then
       WesternSingle = WesternSingle + 1
    End If
    If (Relation1$ = "Divorced") then
       WesternDivorced = WesternDivorced + 1
    End If
    If (Relation1$ = "Seperated") then
       WesternSeperated = WesternSeperated + 1
    End If
Case Else
    Print "You might be from the midwestern states"
    If (Relation1$ = "Married") then
       MidwesternMarried = MidwesternMarried + 1
    End If
    If (Relation1$ = "Single") then
       MidwesternSingle = MidwesternSingle + 1
    End If
    If (Relation1$ = "Divorced") then
       MidwesternDivorced = MidwesternDivorced + 1
    End If
    If (Relation1$ = "Seperated") then
       MidwesternSeperated = MidwesternSeperated + 1
    End If
End Select
Print "The number of people married in the midwestern states is " ; MidwesternMarried
Print "The number of people single in the midwestern states is " ; MidwesternSingle
Print "The number of people divorced in the midwestern states is " ; MidwesternDivorced
Print "The number of people separated in the Western states is " ; MidwesternSeperated
Print "The number of people married in the Western states is " ; WesternMarried
Print "The number of people single in the Western states is " ; WesternSingle
Print "The number of people divorced in the Western states is " ; WesternDivorced
Print "The number of people separated in the Western states is " ; WesternSeperated
End

Update: When I saw "basic" in the title I assumed you meant VB. I have now learned BASIC is actually the language that VB is based off of... Sorry for the confusion.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top