473,326 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Is this a valid code?

Hello,

I made this function so that it can return 1 or 2 where 1 either equal
PieIX or Mendonta or 2 equal either PieIX or Mendonta. Let me go
further in details...in the program it shows all Inventory information
in the datagrid and one column in the datagrid there is a combo box
where I can choose either PieIX or Mendonta and depending on which of
those I select first would determine wether 1 is pieIx and 2 Mendonta
or 1 is Mendonta or 2 is PieIX. For example as below:

ItemNumber AlbumTitle Fulfillment
BO 2222 Best of Poco Lives Mendonta
BO 3333 BoulderDash PieIX

The function below should return 1 for mendonta and 2 for pieIX but if
I decided to do this instead:

ItemNumber AlbumTitle Fulfillment
BO 2222 Best of Poco Lives PieIX
BO 3333 BoulderDash Mendonta

Now this function below should return 1 for PieIX and 2 for Mendonta,
I have this problem what if the function causes a malfunction and then
returns both 1 and 2 PieIX or 1,2 Mendonta, etc, so I just wanted an
outside eye to tell me if there is any bug in my coding? Thanks in
advance.
Below is my code:

Private Function getFulfillment(ByVal strFulfillment As String) As
Integer
Dim intCounter As Integer = Nothing
Dim blAgain As Boolean = False

tryAgain:
If strFulfillment = "Lasalle" Then Exit Function

If strFulfillment = "" Then Exit Function

If blAgain = True Then
blAgain = False
If objTypes(0).strName = objTypes(1).strName Then Return 1
If objTypes(0).strName = "" And objTypes(1).strName <""
Then Return 2
If objTypes(0).strName <"" And objTypes(1).strName = ""
Then Return 1

End If

If objTypes(bytNextFulfillment).strName = "" Then

If objTypes(0).strName = "Pie-IX" And objTypes(1).strName
= "Pie-IX" Then GoTo COMPLETE
If objTypes(1).strName = "Mendota" And objTypes(1).strName
= "Mendota" Then GoTo COMPLETE

intNewValue = intNewValue + 1
If intNewValue 2 Then intNewValue = 2
If bytNextFulfillment 1 Then bytNextFulfillment = 1

If objTypes(bytNextFulfillment).strName = "" Then
objTypes(bytNextFulfillment).bytType = intNewValue
objTypes(bytNextFulfillment).strName = strFulfillment
bytNextFulfillment = bytNextFulfillment + 1

End If
End If

If objTypes(0).strName = "Pie-IX" And objTypes(1).strName =
"Pie-IX" Then objTypes(1).strName = "" : bytNextFulfillment = 0 :
blAgain = True : GoTo tryAgain
If objTypes(0).strName = "Mendota" And objTypes(1).strName =
"Mendota" Then objTypes(1).strName = "" : bytNextFulfillment = 0 :
blAgain = True : GoTo tryAgain
COMPLETE:
If bytNextFulfillment 1 Then bytNextFulfillment = 1

For intCounter = 0 To 1
If objTypes(intCounter).strName = strFulfillment Then
Return objTypes(intCounter).bytType
Next intCounter

End Function

Apr 9 '07 #1
8 1323
Hi,

Your code does not compile, so I can't say for sure if your real code will work, but I can say you won't ever get both 1 and 2 or 1,2 from this function. Once you return a value (return 1 or return 2), that's it. Of, and Exit Function is equivalent of Return whatever value 'getFullfillment' holds, which would be the default Integer value 0, I believe. Thenagain, VB.Net is not my area, so I may be wrong.

I would probably not use Labels and Goto statements, and it looks to me like you are overcomplicating things quite a bit, but I see nothing particularly wrong with your code.

objTypes is undefined, bytNextFulfillment is undefined, intNewValue is undefined.
On Mon, 09 Apr 2007 22:28:18 +0200, <am******@gmail.comwrote:
Hello,

I made this function so that it can return 1 or 2 where 1 either equal
PieIX or Mendonta or 2 equal either PieIX or Mendonta. Let me go
further in details...in the program it shows all Inventory information
in the datagrid and one column in the datagrid there is a combo box
where I can choose either PieIX or Mendonta and depending on which of
those I select first would determine wether 1 is pieIx and 2 Mendonta
or 1 is Mendonta or 2 is PieIX. For example as below:

ItemNumber AlbumTitle Fulfillment
BO 2222 Best of Poco Lives Mendonta
BO 3333 BoulderDash PieIX

The function below should return 1 for mendonta and 2 for pieIX but if
I decided to do this instead:

ItemNumber AlbumTitle Fulfillment
BO 2222 Best of Poco Lives PieIX
BO 3333 BoulderDash Mendonta

Now this function below should return 1 for PieIX and 2 for Mendonta,
I have this problem what if the function causes a malfunction and then
returns both 1 and 2 PieIX or 1,2 Mendonta, etc, so I just wanted an
outside eye to tell me if there is any bug in my coding? Thanks in
advance.
Below is my code:

Private Function getFulfillment(ByVal strFulfillment As String) As
Integer
Dim intCounter As Integer = Nothing
Dim blAgain As Boolean = False

tryAgain:
If strFulfillment = "Lasalle" Then Exit Function

If strFulfillment = "" Then Exit Function

If blAgain = True Then
blAgain = False
If objTypes(0).strName = objTypes(1).strName Then Return1
If objTypes(0).strName = "" And objTypes(1).strName <""
Then Return 2
If objTypes(0).strName <"" And objTypes(1).strName = ""
Then Return 1

End If

If objTypes(bytNextFulfillment).strName = "" Then

If objTypes(0).strName = "Pie-IX" And objTypes(1).strName
= "Pie-IX" Then GoTo COMPLETE
If objTypes(1).strName = "Mendota" And objTypes(1).strName
= "Mendota" Then GoTo COMPLETE

intNewValue = intNewValue + 1
If intNewValue 2 Then intNewValue = 2
If bytNextFulfillment 1 Then bytNextFulfillment = 1

If objTypes(bytNextFulfillment).strName = "" Then
objTypes(bytNextFulfillment).bytType = intNewValue
objTypes(bytNextFulfillment).strName = strFulfillment
bytNextFulfillment = bytNextFulfillment + 1

End If
End If

If objTypes(0).strName = "Pie-IX" And objTypes(1).strName =
"Pie-IX" Then objTypes(1).strName = "" : bytNextFulfillment = 0 :
blAgain = True : GoTo tryAgain
If objTypes(0).strName = "Mendota" And objTypes(1).strName =
"Mendota" Then objTypes(1).strName = "" : bytNextFulfillment = 0 :
blAgain = True : GoTo tryAgain
COMPLETE:
If bytNextFulfillment 1 Then bytNextFulfillment = 1

For intCounter = 0 To 1
If objTypes(intCounter).strName = strFulfillment Then
Return objTypes(intCounter).bytType
Next intCounter

End Function



--
Happy coding!
Morten Wennevik [C# MVP]
Apr 10 '07 #2
You cannot take my code as is and compile it there as so many other
functions and variables out there are needed to get this code working.
I just wanted to know if you follow the steps, one by one (as if you
are the computer) and see the logic if it works.
On Apr 10, 12:14 pm, "Morten Wennevik [C# MVP]"
<MortenWenne...@hotmail.comwrote:
Hi,

Your code does not compile, so I can't say for sure if your real code will work, but I can say you won't ever get both 1 and 2 or 1,2 from this function. Once you return a value (return 1 or return 2), that's it. Of, and Exit Function is equivalent of Return whatever value 'getFullfillment' holds, which would be the default Integer value 0, I believe. Then again, VB.Net is not my area, so I may be wrong.

I would probably not use Labels and Goto statements, and it looks to me like you are overcomplicating things quite a bit, but I see nothing particularly wrong with your code.

objTypes is undefined, bytNextFulfillment is undefined, intNewValue is undefined.

On Mon, 09 Apr 2007 22:28:18 +0200, <amiga...@gmail.comwrote:
Hello,
I made this function so that it can return 1 or 2 where 1 either equal
PieIX or Mendonta or 2 equal either PieIX or Mendonta. Let me go
further in details...in the program it shows all Inventory information
in the datagrid and one column in the datagrid there is a combo box
where I can choose either PieIX or Mendonta and depending on which of
those I select first would determine wether 1 is pieIx and 2 Mendonta
or 1 is Mendonta or 2 is PieIX. For example as below:
ItemNumber AlbumTitle Fulfillment
BO 2222 Best of Poco Lives Mendonta
BO 3333 BoulderDash PieIX
The function below should return 1 for mendonta and 2 for pieIX but if
I decided to do this instead:
ItemNumber AlbumTitle Fulfillment
BO 2222 Best of Poco Lives PieIX
BO 3333 BoulderDash Mendonta
Now this function below should return 1 for PieIX and 2 for Mendonta,
I have this problem what if the function causes a malfunction and then
returns both 1 and 2 PieIX or 1,2 Mendonta, etc, so I just wanted an
outside eye to tell me if there is any bug in my coding? Thanks in
advance.
Below is my code:
Private Function getFulfillment(ByVal strFulfillment As String) As
Integer
Dim intCounter As Integer = Nothing
Dim blAgain As Boolean = False
tryAgain:
If strFulfillment = "Lasalle" Then Exit Function
If strFulfillment = "" Then Exit Function
If blAgain = True Then
blAgain = False
If objTypes(0).strName = objTypes(1).strName Then Return 1
If objTypes(0).strName = "" And objTypes(1).strName <""
Then Return 2
If objTypes(0).strName <"" And objTypes(1).strName = ""
Then Return 1
End If
If objTypes(bytNextFulfillment).strName = "" Then
If objTypes(0).strName = "Pie-IX" And objTypes(1).strName
= "Pie-IX" Then GoTo COMPLETE
If objTypes(1).strName = "Mendota" And objTypes(1).strName
= "Mendota" Then GoTo COMPLETE
intNewValue = intNewValue + 1
If intNewValue 2 Then intNewValue = 2
If bytNextFulfillment 1 Then bytNextFulfillment = 1
If objTypes(bytNextFulfillment).strName = "" Then
objTypes(bytNextFulfillment).bytType = intNewValue
objTypes(bytNextFulfillment).strName = strFulfillment
bytNextFulfillment = bytNextFulfillment + 1
End If
End If
If objTypes(0).strName = "Pie-IX" And objTypes(1).strName =
"Pie-IX" Then objTypes(1).strName = "" : bytNextFulfillment = 0 :
blAgain = True : GoTo tryAgain
If objTypes(0).strName = "Mendota" And objTypes(1).strName =
"Mendota" Then objTypes(1).strName = "" : bytNextFulfillment = 0 :
blAgain = True : GoTo tryAgain
COMPLETE:
If bytNextFulfillment 1 Then bytNextFulfillment = 1
For intCounter = 0 To 1
If objTypes(intCounter).strName = strFulfillment Then
Return objTypes(intCounter).bytType
Next intCounter
End Function

--
Happy coding!
Morten Wennevik [C# MVP]

Apr 10 '07 #3
But you said I over complicate things with this code. I am just
curious, what other method you would approach where 1 is either PieIX,
Mendonta or 2 is either PieIx, Mendota and what ever the value of 1 is
it cannot be the same in value of 2?

Apr 10 '07 #4
First of all, the GOTO statement is so 1990, dont use it, bad coding!
Instead think of functions where you use GOTO.

What you want to do is check wether a string = "Pie-IX" or "Mendota" where
pie-ix=1 and mendota=2?

Private Function checkString(ByVal str as string) As Integer
{
if str="Pie-IX" then
return 1
else'if str="Mandota"
return 2
end if
}

Figa

"am******@gmail.com" wrote:
Hello,

I made this function so that it can return 1 or 2 where 1 either equal
PieIX or Mendonta or 2 equal either PieIX or Mendonta. Let me go
further in details...in the program it shows all Inventory information
in the datagrid and one column in the datagrid there is a combo box
where I can choose either PieIX or Mendonta and depending on which of
those I select first would determine wether 1 is pieIx and 2 Mendonta
or 1 is Mendonta or 2 is PieIX. For example as below:

ItemNumber AlbumTitle Fulfillment
BO 2222 Best of Poco Lives Mendonta
BO 3333 BoulderDash PieIX

The function below should return 1 for mendonta and 2 for pieIX but if
I decided to do this instead:

ItemNumber AlbumTitle Fulfillment
BO 2222 Best of Poco Lives PieIX
BO 3333 BoulderDash Mendonta

Now this function below should return 1 for PieIX and 2 for Mendonta,
I have this problem what if the function causes a malfunction and then
returns both 1 and 2 PieIX or 1,2 Mendonta, etc, so I just wanted an
outside eye to tell me if there is any bug in my coding? Thanks in
advance.
Below is my code:

Private Function getFulfillment(ByVal strFulfillment As String) As
Integer
Dim intCounter As Integer = Nothing
Dim blAgain As Boolean = False

tryAgain:
If strFulfillment = "Lasalle" Then Exit Function

If strFulfillment = "" Then Exit Function

If blAgain = True Then
blAgain = False
If objTypes(0).strName = objTypes(1).strName Then Return 1
If objTypes(0).strName = "" And objTypes(1).strName <""
Then Return 2
If objTypes(0).strName <"" And objTypes(1).strName = ""
Then Return 1

End If

If objTypes(bytNextFulfillment).strName = "" Then

If objTypes(0).strName = "Pie-IX" And objTypes(1).strName
= "Pie-IX" Then GoTo COMPLETE
If objTypes(1).strName = "Mendota" And objTypes(1).strName
= "Mendota" Then GoTo COMPLETE

intNewValue = intNewValue + 1
If intNewValue 2 Then intNewValue = 2
If bytNextFulfillment 1 Then bytNextFulfillment = 1

If objTypes(bytNextFulfillment).strName = "" Then
objTypes(bytNextFulfillment).bytType = intNewValue
objTypes(bytNextFulfillment).strName = strFulfillment
bytNextFulfillment = bytNextFulfillment + 1

End If
End If

If objTypes(0).strName = "Pie-IX" And objTypes(1).strName =
"Pie-IX" Then objTypes(1).strName = "" : bytNextFulfillment = 0 :
blAgain = True : GoTo tryAgain
If objTypes(0).strName = "Mendota" And objTypes(1).strName =
"Mendota" Then objTypes(1).strName = "" : bytNextFulfillment = 0 :
blAgain = True : GoTo tryAgain
COMPLETE:
If bytNextFulfillment 1 Then bytNextFulfillment = 1

For intCounter = 0 To 1
If objTypes(intCounter).strName = strFulfillment Then
Return objTypes(intCounter).bytType
Next intCounter

End Function

Apr 11 '07 #5
But that is the thing Pie-IX isn't necessarly 1 and Mandota 2.

For example I can chose this list

1) PieIX
2) PieIX
3) Mandota
4) Mandota

in this scenario PieIX IS ONE and Mandota is TWO

but if it is like this:

1) Mandota
2) PieIX
3) PieIX
4) Mandota

then Mandota is ONE and PieIX is two and all the Mandotas there in 1
and 4 is equal to 1 and PieIX in 2,3 equal to 2 the same goes to the
preview list 1,2 for PieIX is 1 and 3,4 for Mandota is 1 but you can
never have PieIX, Mandota to be 1 or PieIX, PieIX to be 1 or Mandota,
PieIX to be 2, or Mandota, Mondota to be 2, etc.
Apr 11 '07 #6
You might want to look into

the contains functionality in gridviews and datagrids
"am******@gmail.com" wrote:
But that is the thing Pie-IX isn't necessarly 1 and Mandota 2.

For example I can chose this list

1) PieIX
2) PieIX
3) Mandota
4) Mandota

in this scenario PieIX IS ONE and Mandota is TWO

but if it is like this:

1) Mandota
2) PieIX
3) PieIX
4) Mandota

then Mandota is ONE and PieIX is two and all the Mandotas there in 1
and 4 is equal to 1 and PieIX in 2,3 equal to 2 the same goes to the
preview list 1,2 for PieIX is 1 and 3,4 for Mandota is 1 but you can
never have PieIX, Mandota to be 1 or PieIX, PieIX to be 1 or Mandota,
PieIX to be 2, or Mandota, Mondota to be 2, etc.
Apr 11 '07 #7


I have did further revision to the code because I noticed some
serious bugs on them and it is like this now:

Private Function getFulfillment(ByVal strFulfillment As String) As
Integer
Dim intCounter As Integer = Nothing
Dim blAgain As Boolean = False

tryAgain:
If strFulfillment = "Lasalle" Then Exit Function

If strFulfillment = "" Then MessageBox.Show("Fulfillment is
null.", "", MessageBoxButtons.OK, MessageBoxIcon.Error) : Exit
Function

If blAgain = True Then
blAgain = False
If objTypes(0).strName = objTypes(1).strName Then Return 1
If objTypes(0).strName = "" And objTypes(1).strName <""
Then Return 2
If objTypes(0).strName <"" And objTypes(1).strName = ""
Then Return 1

End If

If objTypes(bytNextFulfillment).strName = "" And
objTypes(0).strName <strFulfillment Then

intNewValue = intNewValue + 1
If intNewValue 2 Then intNewValue = 2
If bytNextFulfillment 1 Then bytNextFulfillment = 1

If objTypes(bytNextFulfillment).strName = "" Then
objTypes(bytNextFulfillment).bytType = intNewValue
objTypes(bytNextFulfillment).strName = strFulfillment
bytNextFulfillment = bytNextFulfillment + 1

End If
End If

If bytNextFulfillment 1 Then bytNextFulfillment = 1
If objTypes(0).strName = objTypes(1).strName Then
objTypes(bytNextFulfillment).strName = "" : bytNextFulfillment = 0 :
blAgain = True : GoTo tryAgain

COMPLETE:

For intCounter = 0 To 1
If objTypes(intCounter).strName = strFulfillment Then
Return objTypes(intCounter).bytType
Next intCounter

End Function

I just need an outside eye to go through the steps of these codes one
by one, please ignore the fact I use GoTo, it is the only time I use
it here and I am content with it. Thanks in advance. (It is not like
the program will seize to function in the future versions of OS
because I use GoTo).

Apr 11 '07 #8


<am******@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
>

I have did further revision to the code because I noticed some
serious bugs on them and it is like this now:

Private Function getFulfillment(ByVal strFulfillment As String) As
Integer
Dim intCounter As Integer = Nothing
Dim blAgain As Boolean = False

tryAgain:
If strFulfillment = "Lasalle" Then Exit Function

If strFulfillment = "" Then MessageBox.Show("Fulfillment is
null.", "", MessageBoxButtons.OK, MessageBoxIcon.Error) : Exit
Function

If blAgain = True Then
blAgain = False
If objTypes(0).strName = objTypes(1).strName Then Return 1
If objTypes(0).strName = "" And objTypes(1).strName <""
Then Return 2
If objTypes(0).strName <"" And objTypes(1).strName = ""
Then Return 1

End If
Why are you setting blnAgain = False here? Right before the GoTo, you are
setting it back to True and between here and there, you aren't using the var
again...so kinda pointless. I didn't step through the logic, that just
jumped out at me :P
Mythran
Apr 12 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: lawrence | last post by:
I have a string which I want to send to eval(). How can I test it ahead of time to make sure it is valid code? I don't want to send it to eval and get parse errors. I want to do something like...
8
by: Hostile17 | last post by:
Consider the following HTML. ---------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html> <head> <meta...
0
by: Tao | last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and tried to test it out. I created an ASP.NET project using the wizard and tried to run it by hitting "F5". I got an exception:...
1
by: jel | last post by:
I ran what was submitted in several forums, but it's not exactly what i'm looking for. I'm dy'n over here. Ah, the frustrations of an amateur programmer. I included the code below in c++. which...
7
by: JR | last post by:
Hey all, I have read part seven of the FAQ and searched for an answer but can not seem to find one. I am trying to do the all too common verify the data type with CIN. The code from the FAQ...
64
by: jrefactors | last post by:
Since C is a subset of C++, so any C code or C libraries (printf(), scanf(), etc...) are valid C++ code. Is that correct? so even though the whole program is written in C, but with .cpp...
23
by: James Aguilar | last post by:
Someone showed me something today that I didn't understand. This doesn't seem like it should be valid C++. Specifically, I don't understand how the commas are accepted after the function...
3
by: Chris | last post by:
Hi, In C# I tried to save a file from a generated file name. Just before launching the dialog I check for a valid file name to be sure. There for I used the method ValidateNames from the save...
8
by: Pieter | last post by:
Hi, I'm having some weird problem using the BackGroundWorker in an Outlook (2003) Add-In, with VB.NET 2005: I'm using the BackGroundWorker to get the info of some mailitems, and after each item...
10
by: dba123 | last post by:
Why am I getting this error for Budget? Error: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: String was not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.