Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Nested IF Statements


I need the following Nested If Statement Solving:

If "exam mark" is less than 40 then state "Exam", if "coursework mark" is less than 40 then state "Coursework", If both "exam mark" & "coursework mark" are less than 40 then state "Both", If they are all over 40 then then state "None"




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Nested If Statements...?
I'm not too sure as to how nested if statements work in visual basic I have the following code...

If (yy > y1) Or (White_Positions(Piece, 2) = 1) Then
Source.Move x1, y1:
If (yy > y1) Then White_Positions(Piece, 1) = White_Positions(Piece, 1) + 1
Else: White_Positions(Piece, 1) = White_Positions(Piece, 1) - 1
End If
End If

this, however, does not seem to be functioning properly... anyone's input would be much appreciated.

Can This Be Done With Nested If Statements?
hello

the data in my files is stored as:

name, type, style (all of which are strings)

and what i would like to do is to be able to search through the list to display a random name - which i can do.

my question regards displaying a random name HOWEVER which has a type or style chosen by the user; so i expect it will be something like using a nested if...loop, although i'm not 100% sure.

any help much appreciated

thanks

r

Nested If Statements
I'm trying to write an insurance program that takes data from an input file like name, gender, type of coverage, age, etc. and gives me a premium based on those variables. I have standard premium rates but my program needs to modify these depending upon some discounts for smoking, etc. I also have the discounts for smokers vs. nonsmokers and club membership vs. non club membership and location (by state code). The premium constants were given but and also vary by age (20-25, 25-30, etc). I'm having one hell of a time writing these nested if statements.
The format is..

e.g.

if gender is male and age is 20-30 then premium is 50.00.
if gender is male and age is 30-40 then premium is 70.00.
....

if he is a non smoker, subtract 10% from premium
if he is a health club member, subtract 5% from premium
.....

if his zip code is 20001 raise premium by 10%
if his zip code is 20002 reducr premium by 10%

......
Then I have to do the same for females in the same program. Can I use a bool for the male vs. female ? Does anyone know any resources where i can get help for this?

Nested If Statements In VB
How do you do nested if statements in VB?

For instance, instead of this:

VB Code:
if i = 4 then...end ifif i = 6 then...end ifif i = 8 then...end if


how could I do something like this:


VB Code:
if i=4 or i=6 or i=8 then---end if

Nested If Statements Syntax
I realize this is a very basic question, but I need to create a custom function in Excel that requires me to write it in VB, which I don't know and don't have any quick access to books about.

Here is what I need to do. I need to define a function zzz based on two values (x & y)

Based on the value of x I need to define multiple constants. (i.e. x10=27 x25=32, x50=44, etc)

Then based on the value of y I need to define 2 constants in terms of the constants defined by x
(i.e. if y<10 then yL=x10 and yh=x25 but if y>10 then yL=x25 and yh=x50)

Once I have yh and yL defined my function is easy and I know how to get it to work (i.e function=yh-yL...its not quite that but you get the drift)

What I can't figure out is how to define multiple constant in one if statement and how they should be nested. In other words, I don't know the proper syntax for the if statements. Any recommendations

Here is what I currently have which isn't compiling correctly:
Function zzz(x,y)
If x=1 then
x10=22
x25=26
x50=30
If x=2 then
x10=27
x25=32
x50=44
if y<10 then
yL=x10
yh=x25
y>10 then
yL=x25
yh=x50
zzz=(yh-yL)
End Function

Nested SHAPE Statements
Does anyone know if you can nest SHAPE commands. It would really be nice if I could show a grandparent/parent/child relationship.

here is my SQL (for the pubs database):

SHAPE {
SELECT
Pub_ID,
pub_name 'Publisher',
City,
State
FROM
pubs..Publishers
} APPEND ({
SHAPE {
SELECT
t.Pub_ID,
t.Title_ID,
t.Title,
t.pubdate 'Published'
FROM
pubs..Titles t (nolock)
} APPEND ({
SELECT
st.stor_name 'Store Name',
s.Title_ID
FROM
pubs..stores st (nolock),
pubs..sales s (nolock)
WHERE
st.stor_id = s.stor_id
}
RELATE Title_ID to Title_ID)
as rsBooksPerStore
} RELATE Pub_ID to Pub_ID)
as rsBookStores




the inner shape works just fine, but when I try to open the whole thing (using native ADO - no controls or anything) I get a "-2147217900 - Syntax error or access violation" error. The idea behind this sql is, I want the list of publishers, the books that each publisher publishes and the stores which carry those books. I know I can get this list using plain joins and such, but I'm trying to nail this data shaping stuff to the wall.

here is my code for opening the recordset:

Dim cn as ADODB.Connection
Dim rsMaster as ADODB.Recordset
Dim rsChild as ADODB.Recordset
Dim sqlShape as string
Dim sqlPubs as string
Dim sqlStores as string
Dim sqlTitles as string
Dim sqlSubShape as string

sqlPubs = "SELECT Pub_ID, pub_name 'Publisher', City, State "
sqlPubs = sqlPubs & "FROM pubs..Publishers"

sqlTitles = "SELECT t.Pub_ID, t.Title_ID, t.Title, t.pubdate 'Published' FROM pubs..Titles t (nolock)"

sqlStores = "SELECT st.stor_name 'Store Name', s.Title_ID "
sqlStores = sqlStores & "FROM pubs..stores st (nolock), "
sqlStores = sqlStores & "pubs..sales s (nolock) "
sqlStores = sqlStores & "WHERE st.stor_id = s.stor_id"

sqlSubShape = "SHAPE {" & sqlTitles & "} APPEND ({" & sqlStores & "} "
sqlSubShape = sqlSubShape & "RELATE Title_ID to Title_ID) as rsBooks"

sqlShape = "SHAPE {" & sqlPubs & "} "
sqlShape = sqlShape & "APPEND ({" & sqlSubShape & "} "
sqlShape = sqlShape & "RELATE Pub_ID to Pub_ID) as rsBookEmps"

set cn = new ADODB.Connection

With cn
.CursorLocation = adUseClient
.ConnectionString = "Provider=MSDataShape;Data Provider=MSDASQL;Data Source=SLCLASM06T;User Id=sa;Password=;Database=Pubs;"
.Open
End With

set rsMaster = new ADODB.Recordset
set rsMaster = cn.Execute(sqlShape)

End Sub




I'm using ADO 2.1, SQL Server 6.5 SP5, VB6 SP3, and WinNT Wkst 4 SP4

If anyone knows of a way to do this, or if this can not be done for sure, I would appreciate it.

thanks,

John

John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org

Problems With Validation (nested If Statements)
Maybe it's late but I just can't see what's wrong with the following:


vb Code:
If IsNumeric(txtMainWidth) Then    If txtMainWidth.Text = "" Then      MsgBox "Please enter a value", vbInformation, "Error"      With lblMainWidth                      .ForeColor = vbRed                      .FontBold = True      txtMainWidth.SetFocus      Exit Sub    Else    If Not IsNumeric(txtMainWidth) Then      MsgBox "Please enter a numeric value", vbInformation, "Error"      With lblMainWidth                      .ForeColor = vbRed                      .FontBold = True      txtMainWidth.SetFocus      Exit Sub     End If  Else    sngRoomWidth = txtMainWidth.Text  End If


I get the error "Else without If"

Nested Select Case Statements .. Possible ?
It may be (it is Monday morning after all !), but I am having trouble nesting a SELECT CASE statement within another.

The syntax looks OK, so I was wondering if I was getting an error due to it not actualyl being possible ?!

My code ....


VB Code:
If KeyCode = vbKeyReturn Then        Select Case QuestionNo            Case 1                If txtAnswer = "C" Or txtAnswer = "D" Then                    Select Case txtAnswer                        Case "C"                            FRMmAIN.lblP1 = "Create Class for Category Ranging"                            V_CreateBy = "C"                            FRMmAIN.fraSelectedParams.Visible = True                            Unload Me                        Case "D"                            FRMmAIN.lblP1 = "Create Class for Department Ranging"                            V_CreateBy = "D"                            FRMmAIN.fraSelectedParams.Visible = True                            Unload Me                    End Select            [b]Case 2[/b]                Select Case txtAnswer                    Case "B"                        FRMmAIN.lblP6 = "Create by Branch"                        BranchOrClass = "B"                        FRMmAIN.fraSelectedParams.Visible = True                        Unload Me                    Case "C"                        FRMmAIN.lblP6 = "Create by Class"                        BranchOrClass = "C"                        FRMmAIN.fraSelectedParams.Visible = True                        Unload Me                End Select            Case 3                Select Case txtAnswer                    Case "B", "A", "R"                        FRMmAIN.fraBranches.Visible = True                    Case "E"                        FRMmAIN.txtOption = ""                        Unload Me                End Select        End Select    End If


The error occurs on the bold bit, and states "Case without Select Case" !

Nested If Statements, Or 1 Large If Statement.
I would like your thoughts in whether several nested If statements are better than 1 large if statement with And s between conditions. Here is the code i could use:

VB Code:
For i = 1 To UBound(sFiles)    If FileExist(Left$(sFiles(i), InStr(1, sFiles(i), ".", vbTextCompare) - 1) & "-" & H1 & ".dat") Then        If FileExist(Left$(sFiles(i), InStr(1, sFiles(i), ".", vbTextCompare) - 1) & "-" & H2 & ".dat") Then            If FileExist(FileH1 = Left$(sFiles(i), InStr(1, sFiles(i), ".", vbTextCompare) - 1) & "-" & H3 & ".dat") Then                iCount = iCount + 1                ReDim Preserve SGFiles(iCount)                SGFiles(iCount) = sFiles(i)                Print #1, SGFiles(iCount)            End If        End If    End IfNext


Or should i stick all those if conditions on one if statement with ands?

Using Array Values In Nested If Statements On My VBScript
I have a VBS that I using to create a phone list. I have a list of names that is pulled from my Active Directory, and I have found a way to alphabetize them (using a bubble sort). The names are in an array which I populated with only the first name and last name of the user, however my form is sorted by other attributes of the account...
So question 1 is do I lose all the other attributes of the record that is being pulled when I place them in the array?

Question 2 is how would I use the entries of the array in my if statement that is nested within a case statement?

Here is a sample of the code that I am using...


Code:
EnumerateUsers(oCont)
Dim oUser
Dim arrNames()
intSize = 0

For Each oUser In oCont


' start bubble sort
ReDim preserve arrNames(intsize)
arrNames(intsize) = oUser.SN & ", " & oUser.GivenName
intSize = intSize + 1
Next

For i = (UBound(arrNames) - 1) to 0 Step -1
For j= 0 to i
If UCase(arrNames(j)) > UCase(arrNames(j+1)) Then
strHolder = arrNames(j+1)
arrNames(j+1)=arrNames(j)
arrNames(j) = StrHolder
End If
Next
'end bubble sort, now all names are in alphabetical order by last name

Select Case LCase(oUser.Class)
Case "user"
If oUser.telephoneNumber <> "" then
If oUser.physicalDeliveryOfficeName = "Wixom" then

If oUser.department = "Engineering" then

sdata = "<tr>"
sdata = sdata & "<td class='list'>" & oUser.GivenName & " " & oUser.SN & "</td>"
sdata = sdata & "<td class='list'>" & oUser.telephoneNumber & "</td>"
sdata = sdata & "</tr>"

wixEng(wixEngRow) = sdata
'wixEngRow = wixEngRow
wixEngRow = wixEngRow + 1

end if

Nested Yes NESTED &"If&" Statements
OK, here's another scratcher. I can't use the "elseif" statement for this, because I'm talking about anothe "if" to execute IF the FIRST IF evaluated to TRUE, not "else" (i.e. false)

My program determines, from the GetCrt$ dealy, if the record in question is red (10) or blue (5). Now, if a record is known to be red, then the program should set the cursor to 10,21 and emit either "RedRock" or "RedRover," depending on whether the "Rover" check box is checked (if it isn't, then RedRock is the default).


CrtSetCursor 10,21
if record = 10 then
if Rover.value = 1 then emit "RedRover" else emit "RedRock"
end if
End if

But I get syntax errors; it doesn't like my consecutive "end ifs," which I figured would be necessary because there are (ideally) two "if" dealies being executed there.

How can I execute an "if" within an "if" ?????

thanks

Nested &"IF&" Statements Not Working.
VB Code:
'Check Main Category to see if any boxes are checked.If cbDOB.Value = vbchecked Or cbInitials.Value = vbchecked Or cbHomeAddress.Value = vbchecked Or cbHomeWorkPhone.Value = vbchecked Then        'Date of Birth    If cbDOB.Value = vbchecked Then    MsgBox "DOB Checked"    End If        'Initials    If cbInitials.Value = vbchecked Then    MsgBox "Initials Checked"    End If        'Home Address    If cbHomeAddress.Value = vbchecked Then    MsgBox "Home Address Checked"    End If        'Home and Work Phone    If cbHomeWorkPhone.Value = vbchecked Then    MsgBox "Home Work Phone Checked"    End If     End If


It is not giving me an error, however it is not popping up any msg boxes when the corresponding checkboxes are checked.

Nested IF
Hi guys,

I mostly work with C++ and I'm having a problem with this. I want to output results based on nested IF.

IF length less than 20 = then break at easynet side
IF length greater than 20 but less than 80 = then break at end at TC
IF length greater than 80 but less than 200 = then break in exchange or TAM problem
IF length greater than 200 = then OK
IF length greater than 5500 = then loop on line or too long


I've tried doing something like this but it keeps giving me errors


If Length < 20 then
text2 = "break at easynet side"
else
If Lenght.....then
else
If Length.....then
else
If Length.....then
else
If Lenght.....then
End If


Thanks for your time.

Nested If's
I have seven checkboxes. I need to verify that at least one of them is chosen. Is there a better way to do this than nested if statements?

Nested For Next
I have a Flexgrid on a form which has 13 rows and 5 columns. I want to total the figures in row 13 and column 5, but I am having problems doing this with a nested loop. I can get a total to appear at the bottom of one column and at the end of one row, using the code show below.

'Total the columns
Dim TotalCol As Single
TotalCol = 0
For RowCounter = 1 To 12
grdTable.Row = RowCounter
grdTable.Col = 1
TotalCol = TotalCol + Val(Mid(grdTable.Text, 2))
Next
grdTable.Row = 13
grdTable.Text = Format(TotalCol, "#,##0.00")

'Total the rows
Dim TotalRow As Single
TotalRow = 0
For ColCounter = 1 To 4
grdTable.Col = ColCounter
grdTable.Row = 1
TotalRow = TotalRow + Val(Mid(grdTable.Text, 2))
Next
grdTable.Col = 5
grdTable.Text = Format(TotalRow, "#,##0.00")

End Sub

I could copy and paste this code and edit it so that totals would appear where I want them, but I thought a For Next loop would be better. I have tried a number of times to achieve what I want to do, but only 0's have appeared in the cells.

Any ideas on this one appreciated.

Thanks

Nested IF
Hi Everyone,

I have another problem. If there is no files in the direcotry I'm searching the code still excutes insted of going to the Else. Anyone no why?


Code:
Private Sub Command1_Click()

'Set Variables to hold Excel Start Up information
Dim MyXl As Excel.Application
Dim ws As Worksheet
Set MyXl = New Excel.Application

'Set Variables to hold new file name information
Dim FileName As String
Dim LastFile As String
Dim NewFileName As String
Dim Path As String
Dim Prefix As String
Dim Extension As String
Dim Number As String
Dim NewPath As String

'Start progress bar timer
Timer1.Enabled = True

'Path for file storage
NewPath = "C:Inventory Pages"

If Dir("c:Inventory Pages", vbDirectory) <> vbNullString Then

'Open Excel Workbook
With MyXl

'Template file Name and Path
.Workbooks.Open "C:TemplateTemplate"

'Show Excel Sheet (This can be removed if excel should be done in background)
.ActiveWorkbook.Activate

'Set active sheet
Set ws = .ActiveWorkbook.Worksheets(1)
ws.Activate

'Stamp current Time and Date to Sheet
ws.Range("B4").Value = Time
ws.Range("F4").Value = Date

'Fill ranges with OPC Variables

'Tank 113
ws.Range("C3").Value = TK113_Trans_Tag
ws.Range("D3").Value = TK113_Trans_Tag
ws.Range("E3").Value = TK113_Trans_Tag
ws.Range("F3").Value = TK113_Trans_Tag

'Find char code of last File in Path
LastFile = Chr$(126)

'Set path for file storage
Path = "C:Inventory Pages"

'This section breaks down the file storage names. For example:
'TestFile0001.txt
'Prefix = "TestFile"
'Extension = ".txt"
'FileName = Dir$(Path & Prefix & "*" & Extension)
'FileName = Dir$(C: emp2 & TestFile & "*" & .txt)

Prefix = "Test"
Extension = ".xls"
FileName = Dir$(Path & Prefix & "*" & Extension)

'Do while
Do While Len(FileName)

If StrComp(FileName, LastFile, vbTextCompare) = 1 Then

LastFile = LCase$(FileName)
FileName = Dir$

End If

Loop

Number = Mid$(LastFile, Len(Prefix) + 1, InStr(LastFile, ".") - Len(Prefix))
Number = Format$(Val(Number) + 1, String$(Len(Number) - 1, "0"))
NewFileName = Prefix & Number & Extension

'Stamp name on label
Label1.Caption = NewFileName

'Stamp File name to Sheet
ws.Range("D4").Value = NewFileName

'Create new file name and save
.ActiveWorkbook.SaveAs FileName:=Path & NewFileName

'Set print area
'.ActiveWorkbook.PrintOut From:=1, to:=1
'.Visible = True

'Close Excel
.Quit

End With

Set MyXl = Nothing

Else

MsgBox "The directory is empty"

End If

End Sub

Nested If Statement
Hi all,

I have 2 lists on 2 different sheets, the first sheet being a longer list. I want to periodically update the second sheet, but only with new entries and only if there is a available space(the second sheet can have a maximum or 5 entries).

Here is some code along the lines that I have been trying to make it work, but am having no luck. I think I need completely different approach to this problem. Any ideas/code would be most welcome.

Cheers


Sub Add_shares()
Dim i As Long
Dim epic As String
Dim qty As Variant
Dim Buy_price As Integer
Dim test As Integer
For i = 7 To 12

If Sheet7.Cells(i, 1).Value = "" Then
If Sheet2.Cells(i, 1).Value = Sheet7.Cells(i, 1).Value Then
'If Sheet2.Cells(i + 1, 1).Value = Sheet7.Cells(i, 1).Value Then
'If Sheet2.Cells(i + 2, 1).Value = Sheet7.Cells(i, 1).Value Then
'If Sheet2.Cells(i + 4, 1).Value = Sheet7.Cells(i, 1).Value Then
'If Sheet2.Cells(i + 4, 1).Value = Sheet7.Cells(i, 1).Value Then GoTo skip Else GoTo proceed
'GoTo skip Else GoTo proceed
'Else: GoTo proceed
'End If
proceed:
Sheet2.Activate
epic = Cells(i, 1)
qty = Cells(i, 2)
buy = Cells(i, 3)
Sheet7.Activate
Cells(i, 1).Value = (epic)
Cells(i, 2).Value = (qty)
Cells(i, 3).Value = (buy)
skip:
Next
End Sub

Nested Classes In VBA
We all know that VBA (i.e. Excel im my case) impliments nested classes like:

Range.Interior.Color=5

but how can I get the same structure with my user-defined classes?

ie) I would like:
MyClass.Files.Open("Path")

but I cannot nest the classes and the best I can do is:
MyClass.Files (one function/sub deep)

Am I missing something here or are nested classes not possible like in .net?

Nested .Find
Is it possible to do a nested .find? For example:


Code:
Sub doMyThing()
Dim initialRng As Range, rng1 As Range, rng2 As Range
Dim firstAddress1 As Range, firstAddress2 As Range

Range("B1").Select
Set initialRng = Selection

Set rng1 = Columns("D:D").Find(Cells(initialRng.Row, 4), LookIn:=xlValues, _
LookAt:=xlWhole)
If Not rng1 Is Nothing Then
Set firstAddress1 = rng1
Do
'Stuff goes here
If Cells(rng1.Row, 5) <> Cells(initialRng.Row, 5) Then
Set rng2 = Columns("E:E").Find(Cells(rng1.Row, 5), _
LookIn:=xlValues, LookAt:=xlWhole)
If Not rng2 Is Nothing Then
Set firstAddress2 = rng2
Do
'Stuff goes here
Set rng2 = Columns("E:E").FindNext(rng2)
Loop While Not rng2 Is Nothing And rng2.Address <> firstAddress2.Address
End If
End If
Set rng1 = Columns("D:D").FindNext(rng1)
Loop While Not rng1 Is Nothing And rng1.Address <> firstAddress1.Address
End If
End Sub
I get an error at 'Loop While Not rng1 Is Nothing And rng1.Address <> firstAddress1.Address'

Error: 'Object variable or with block variable not not set'

This occurs with the rng1.Address part of the line.
I can get a single .Find to work, but when I 'nest' the find statements, I get the error. Please help.

Nested IF Limit?
Hi

I was just playing with writing my program yesterday, when I came accross this. In my program I have a nested IF statement, with quite a few if's in it, and after a certain point it seems the code isn't executed...

What I'm tryng to say is that after a point, it is as if my code was

..
else
end if
...

rather than having more conditions.

I have never used this many If statements together before so I never came accross this before. Also I'd like to add that the code that isn't being executed, works fine when I move it to become one of the first IF's in the nested if's.. Sorry if my explanation isn't clear

By the way, I don't know if the corrent name for what I'm talking about is "nested IFs", so for those who maye dont use that terminology, what I mean is liek multiple If's.. such as:

Code:
If <condition> = True then
'do something
else
If <condition2> = false then
'do something different
else
if <condition3> = "DevOtion" then
'do something
else
end if
end if
end if

So what I'm asking is, is there a limit to how many If statements you can use like this? If so, can anyone reccomend a method to get around it?

All help or suggestions arE Much appreciated

Nested If Limitations
Hello All:

I'm looking for a UDF that will overcome the 7 nested if limitation. I need a UDF that will do something similar to:

IF(BV2 <> "", BV2,
IF BR2 <> "", BR2
IF(BN2 <> "", BN2
IF(BJ2 <> "", BJw
IF(BF2 <> "", BF2
IF(BB2 <> "", BB2
IF(AX2 <> "", AX2
IF(AT2 <> "", AT2
IF(AP2 <> "", AP2
IF(AL2 <> "", AL2
IF(AH2 <> "", AH2
IF(AD2 <> "", AD2, ""

Is this possible? Any help is appreciated!

Nested Class
Hello,

how do you create a nested class, or to be more precise, a nested property?
i.e. I would like to create such properties as 'date of entry', 'location' etc. within the property 'records', within the class 'patient'.

Thank you

Nested Loops
I want my program to do something like this:


Code:
do untill endprgram = true ''''''''''''''''''''''''''''''''''make this do for

do until time= 5 seconds

wait a second

loop
if time = 25 then endprogram = true

loop'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''this loop

So in this example, I want this to wait 5 seconds and then check if it has been 25 seconds

Nested Classes
Hi,

I am stuck for a few days trying to solve my data structure problem. I am making a class hierarchy for a GUI to store my data and methods for somekind of drawing program.

The basic elements are lines, circles, symbols and text. Each of them are stored in a different collection. Together, with some extra data they make up a map. A collection of maps make up a project. The top is a collection of projects.

I used the add-in class builder to create it but got stuck. In order to debug I created a test program and with babysteps I increased the levels of hierarchy. In that testcase everything worked.

Now here is my problem. For some kind of reason the collection of symbols 'colSymbols' doesn't work. As soon as I add an instance of the symbol-class the collection Symbol.count goes up one but there does not appear an item(x) in the watch list when you debug it. Only in the private list mCol you can find it back.

To illustrate it I added my test project. Hopefully you can help me out. Maybe some one has an example of nested classes that works and I can use that as reference.

- Dutch-O

How Many Nested Procedures??
Are there any rules of thumb regarding how deep not to go when nesting procedure and function calls. Breaking repeated code in separate procedures makes sense, but that gets messy when you have many, many procedures.

I recall reading that a procedure should perform one thing. I suppose creating a class could clean things up a lot. Something else to learn. Cool!

Comments??

Nested Do While Loops???
hi i'm having some trouble with my nested loops this is what i have at the minute:

Code:

Do While Not rs.EOF

If rs!sectionno = 1 Then

If Not rscrops.EOF Then rscrops.MoveFirst

Do While Not rscrops.EOF

If rscrops!crop = rs!crop Then Command1(rs!rowno - 1).BackColor = rscrops!colour

rscrops.MoveNext

Loop

rs.MoveNext

Loop
but it complains that the last loop has no do while, but it's supposed to be for the first do while.
Can anyone give me a pointer in the right direction......???

Need Help Understanding Nested Ifs
Heres the problem. I'm sort of a beginner to VB (ok, I am a beginner, I admit it), and my professor has had a problem come up where she can not teach us this section. I need to understand nested if statements so that I can use it in a project. At least a rough over view, so i can understand the things.

My project is about 20 option buttons. I want it so that is one of those options is selected and numbers (that are to be averaged) are entered in text boxes, that a nested if statement will be able to be used. (I won't use your code, just need an example of how they are used in codes, so that I will be able to write my own for my project).

I am defenitly not looking for an easy way out, I am sencir (yes I know I can't spell). If someone can explain how to use these darn things, then I will be grateful, if not so be it, back to ripping my hair out to figure it out . Have a good day, later.

ThePowerOfCheese

Nested Loop
VB6, Access

What I have...(1 table)
ThisClaimNumberThatClaimNumber
CN5005..............CN5006
CN5005..............CN5007
CN5005..............CN5008
CN5005..............CN5009

What I need...
I need to know how to add new records based on ThatClaimNumber field. (ie ThisClaimNumber is what is referenced in code, but I need to link together) Simply put after code is executed I need the same table to look like this...
ThisClaimNumber......ThatClaimNumber
CN5005..................CN5006
CN5005..................CN5007
CN5005..................CN5008
CN5005..................CN5009

CN5006..................CN5005
CN5006..................CN5007
CN5006..................CN5008
CN5006..................CN5009

CN5007..................CN5005
CN5007..................CN5006
CN5007..................CN5008
CN5007..................CN5009

CN5008..................CN5005
CN5008..................CN5006
CN5008..................CN5007
CN5008..................CN5009

CN5009..................CN5005
CN5009..................CN5006
CN5009..................CN5007
CN5009..................CN5008

Thanks.

Nested Classes
I'm having trouble with creating instances of classes within classes, to use object.notation to set public variables by what the programmer selected as he goes along, like:

Public Organism As New OrganismClass
Public Insect As New InsectClass
Public Mammal As New MammalClass
Public Reptile As New ReptileClass
Public Primate As New PrimateClass
Public Canine As New CanineClass etc...

Public aOrganism As Boolean
Public aReptile As Boolean
Public aMammal As Boolean
Public aHuman As Boolean
Public aDog As Boolean etc...

then:

Organism.Reptile.Snake.Poisonous would set aOrganism = true, aReptile = true, aMammal = false, aHuman = false etc... depending on the object.notation path the programmer used (with the prompts in the IDE). I'm basically trying to make a whole lot of stuff happen behind the scenes depending on the object.notation used by the programmer. One thing to note is I am not trying to specifically set properties OF a class, but rather set public variables as the programmer uses object.notation to describe what he is trying to do, by making selections as he goes along. Just like if you could use nested Type statements without the prompt falling off. I tried Type, but the prompts fell off at the second level. I want to nest it to about 15 levels with up to 20 selections on each level. I tried to make class modules for each level, which I must have screwed up somehow, and then I tried to make a class for each entry in each level, but that didn't work either (and it would have turned into hundreds of classes). I've made quite a few classes without much trouble, but they were pretty simple. I must be doing something fundamentally wrong. Can anyone give me a really simple step by step lesson on nesting classes so the object.notation remains intact? Or some other approach. What this is supposed to do is set about 200 variables which determine what a few subs do by prompts in the object.notation. With a selection at each level 2 to about 40 settings can be extrapolated. A class at each level would be great because I could have the extrapolations contained in the class. Thanks.

Nested Loops
Can you provide me with the proper sytax for a nested do loop. I can't seem to get the nested loop in properly. Thanks I'm sorry i should have given you the error message I am getting. Combile error loop without do.

Nested For Next Loops
Hello,
I am a newbie that has been trying to self teach myself VB6. On the section of For Next I got it down where it's not nested, and with help I have learned to understand the nesting, but as with everything in life something comes along and trips you up.There is a problem in the book I've been using that wants a picture of a diamond out of asterisks.

In the first row there would be 1 asterisk, the second there would be three with the second one centered the third row Five the third centered, and then in the subsequent rows they decline by 2 to form the diamond.

I've tried multiple combinations of For/Next I tried using space$(x) , if thans , I even got desparate to use & mod statements to try and get the spaces correctly.

I'm hoping someone can point me in the right direction.

End Sub Nested In A If Then Statement
Why can't you nest an End Sub within an if statement?


Code:
Blah blah blah
If X = 1 then
Blah Blah Blah
End Sub
End if
Blah Blah Blah

Nested Queries
I currently porting an Access Database to SQL Server 2000, but have run into difficulties in writing the stored procedures for nested queries. here is an example:

this is the SQL for qry1_e

Code:
PARAMETERS lngUserID Long;
SELECT Max(PASSWORDS.PASS_ID) AS LatestID, PASSWORDS.USER_ID
FROM PASSWORDS
GROUP BY PASSWORDS.USER_ID
HAVING (((PASSWORDS.USER_ID)=[lngUserID]));
and this is the query that uses it as nested query

Code:
SELECT PASSWORDS.PASSWORD, PASSWORDS.ENCRYPT_ID, PASSWORDS.USER_ID, PASSWORDS.NON_EXPIRY
FROM PASSWORDS INNER JOIN qry1_e ON PASSWORDS.PASS_ID = qry1_e.LatestID;
because it is a while since I have used any version of SQL Server I am having trouble remembering how to rewrite this.

Any pointers would be greatly received

Need Help With Nested Select
Hi,

As this is my first post, I'll do a brief introduction about myself I'm currently studying in Malaysia for my IT diploma certificate. Curently, I'm trying to complete a year-end software development project and am stuck with an sql query statement. I did a search through the previous posts in this forum for a solution but couldn't manage to find a way to solve it.

Here's the situation. There are two tables; bookingfile and schedulefile. I need to select a field, ScheduleNo, in the schedulefile, which will be on a certain date.
Then select a few fields which have the same corresponding ScheduleNo in the bookingfile table.

Here's the current query:

Code:
strsql = "SELECT ScheduleNo, BusNo FROM BookingFile WHERE ScheduleNo IN" _
& "(SELECT ScheduleNo FROM ScheduleFile WHERE Day(EstimatedDepartureDate) = '" & query_date & "' AND Month(EstimatedDepartureDate) = '" & query_month & "' " _
& " AND Year(EstimatedDepartureDate) = '" & query_year & "')"

The inner select seems to be working because I'm getting getting the appropriate schedule numbers from the dates specified. But when combined witht outer select, it gave out this error: " Invalid Memo, OLE, or Hyperlink Object in subquery 'ScheduleNo'. "

The database file used is access.

I would greatly appreciate any help from you guys. Thanks.

Nested Right Joins? Help Plz!
Hola,

I'm trying to join 3 tables together in a select statement where each table may or may not have subsequent fields in the next table. The relationships go like :

[orders] (1) ---> (0-1) Contracts (1) ---> (0-1) [Boxes]

As in, an Order can have a Contract, and a Contract can have a Box.

I know I need to do this using RIGHT JOINs. I can get all orders to come up with any related contracts using:


Code:
SELECT Orders.OrderID, Contracts.ContractNumber
FROM Contracts RIGHT JOIN Orders ON Contracts.ContractNumber = Orders.ContractNumber;
And get the same thing for all contracts and any boxes using:


Code:
SELECT Contracts.ContractNumber, Boxes.BoxNumber
FROM Contracts LEFT JOIN Boxes ON Contracts.ContractNumber = Boxes.ContractNumber;
What I want though is to integrate these 2 queries somehow so that I get one big table listing all orders as the priority. This is where my SQL falls short.

Any help would be much appreciate!

DB : Access 2000 using Jet.

Nested Cursors
Does anyone know where I could find a good how-to on nested cursors?
It is a school project (Microsoft SQL server)

Thank you,
Bill

Help On Nested Recordsets
Hi everybody!

I'm new here.

I have one recordset, exemple:

Dim cmd As New Command
Dim rs As New Recordset

With cmd
.ActiveConnection = "DSN=MyDSN;"
.CommandType = adCmdText
.CommandText = "SELECT TABLE1.FIELD1, TABLE1.FIELD2, TABLE2.FIELD2 " & _
"FROM TABLE1 INNER JOIN TABLE2 ON TABLE1.FIELD1 = TABLE2.FIELD1 " & _
"WHERRE TABLE1.FIELD3 BETWEEN '" & Me.txt1 & "' AND '" & Me.txt2 & "'"
End With

With rs
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open cmd
End With

'Here y have the result inside the rs.
'But with one query can't do almost nothing, so the intention is to use this rs in
'conjunction vith other table to build another query (like in MS Access), something like this:

"SELECT rs.FIELD1, rs.FIELD2, TABLE5.FIELD1 FROM rs INNER JOIN TABLE5 ON " & _
"rs.FIELD1 = TABLE5.FIELD2 WHERE TABLE5.FIELD1 = '" & Me.txt3 & "'"

Questions:

1. How can write the second query? How can access one existing rs in a new SELECT statement?

2. Do I need for second query one new rs object? Or one new command object?

3. In ACCESS, when I need to build one process, let's say to calculate one stock, can use
in this process even 6 or more nested queries, and each intermediary query can be used
to build another, and another query. How can I make this in VB?

4. How it is better, writing stored procedures or writing vb code like above?

5. Can somebody give me any links, something, where I can read about this type of "CONSTRUCTIONS"
in visual basic, with more than one query ?

Help me, please.

Thank's a lot for any sugestion.

PS. I'm not native english speaker, so excuse my poor english.

koci,

Tarragona, Spain.

Nested DataRepeater
Hi, I wanted to display a DataRepeater inside another DataRepeater. I can bind the data to the 'outside' one. How can i bind the data to the one inside??

Nested Filtering?
Hi [vb6; DAO; MSAccess]

I need to filter a recordset then filter it again. does this work by simply

Code:
db_rs.Filter = "(field1 = string1)"
db_rs.Movefirst
string2 = field2
db_rs.Filter = "(field2 = string2)"


so basically the first set is filtered, and a field fromthe first record of the filtered set is used to create a filtered "sub-set" of the originall filter.

should this work or is there a better way to do it?
thanks


just thought maybe it should be:

Code:
db_rs.Filter = "(field1 = string1)"
db_rs.Movefirst
string2 = field2
db_rs.Filter = "((field1 = string1) AND (field2 = string2))"


??

Nested Order In SQL
Hey, I need to beable to run an SQL statment that has a NESTED ORDER BY:

In addition to ordering just by the username, I would like to order by the username, but then have each username be in the order of their DateFilled...

here is an example


Username Date (month/day/year)
john 010104
john 010504
john 033104
matt 021503
matt 051504
matt 062104

Understand?

Hopefully this is possible to be done with one sql statement.

Are Nested Loops Possible ?
Such as



Code:
For a = 1 to a = 100

if a = 1 then
{ do this...}

next a

Nested Functions - IS IT POSSIBLE??
I'm trying to figure out a way to nest functions with parameters.

For example take a simple function such as Rate Of Change (fROC).

To be able to nest the rate of change function within itself the call might look like:



VB Code:
Answer =  fROC(fROC(PriceNow, 10), 20)  ------------------------- Private Function fROC(sngPrice() As Single, Length As Integer) As Single'Rate of Change    '---------    If sngPrice(Length) <> 0 Then      fROC = (sngPrice(0) / sngPrice(Length) - 1) * 100   Else      fROC = 0   End If End Function



Where the problem arises is that the outside call is being passed
a function, whereas the 1st parameter of the function is expecting an array of singles.

If I used a parsing routine to parse out the functions then:

a. How would I set up the return values from the inside function since the outside function needs an array of single values in order to compute its value??

b. How do I get the calling function to the parsing routine since the line of code should be the calling routine as written???

ANY HELP WOULD BE GREATLY APPRECIATED

Thanks
David

Nested Query
can I write nested query in vb when I have database in access created through virtual datamanager. I have a table where I have a combo(for name so that it gets updated fr db), memid (members id,text box) &another tbl where I have memid & fmembers. Now when I click on fmembers the records fr 2 table gets retrived acc to the memid. what i want is when I click a members name his member id should be retrieved fr Ist table & all persons having the same id in table 2 should get loaded in fmembers combo box. How I can do it.

Nested Subreports
Hi

I am developing a system that has a hierachical system of data - the hierachical flex grid control creates the perfect on screen view of this data.

My problem is how do I make a report that looks like this?

I thought nested subreports would work well but MS Access only allows 2 nested subreports and the version 6 of crystal reports only allows 1 nested subreport.

If anyone can help I would be very appreciative.

Thanks.

Simon

Nested If Horror!
im tryin to make a 5 long nested if, but it isnt workin... please help

Nested For Looping
i want to fill a grid

i need help with the nested for looping to
fill the first column-second row with a count: ie: 1,2,3, etc. ( the first row is my header info)
and then starting in the second column through column whatever, my data

thanks for all help,

Help Please, Nested Loops.
how do i use the (counter)command to do a nested loop.
eg. for counter=1 to 10
Print"*";
Next counter
How do i use an other counter to loop the program so that it prints a 10 by 10 square of *.
Thank you for your help

Nested Directories
I've been trying to create nested directories as per the example shown mvps.org/vbnet/code/fileapi/nested.htm
All the code runs, and i get no error meassages and get the msgbox stating that n directories have been made but the directories are not shown in the Explorer. I'm trying to implement the code using VBA

[Edited by Tray on 03-20-2000 at 06:40 PM]

What Is A Nested Loop?
I've been advised to use this technique for a program but I'm unsure as to what it is?

Copyright 2005-08 www.BigResource.com, All rights reserved