I have a bunch of params:
InputParam1, InputParam2, InputParam3, etc...
I would like to loop through them instead of writing out code for each one, but am having some issues getting it to work correctly.
Here is what I have so far: -
Dim iCount As Integer
-
Dim objTemp As Object
-
Dim strTemp As String
-
-
For iCount = 1 To 50
-
objTemp = "InputParam" & iCount.ToString
-
strTemp = CStr(objTemp)
-
Next
-
The major issue with what I have is that I cannot assign the string to the object and just creating the string gives me an error too.
10 5456
I have a bunch of params:
InputParam1, InputParam2, InputParam3, etc...
I would like to loop through them instead of writing out code for each one, but am having some issues getting it to work correctly.
Here is what I have so far: -
Dim iCount As Integer
-
Dim objTemp As Object
-
Dim strTemp As String
-
-
For iCount = 1 To 50
-
objTemp = "InputParam" & iCount.ToString
-
strTemp = CStr(objTemp)
-
Next
-
The major issue with what I have is that I cannot assign the string to the object and just creating the string gives me an error too.
Hm. I know what you are talking about and I have done this with ASP pages before but with using text boxes.
So I guess I'm confused, how are you collecting these input parameters?
If you are collecting them from textboxes why not make an array of textboxes? Then just loop through those instead of looping through named parameters?
Something like : -
For icount = 1 to 50
-
strTemp = txtParameter(icount).Text
-
Next
-
-
I guess another thing I was wondering was if this was VB.NET or VB6.0? I am not sure that .ToString is available in VB6.0 ?
It is unfortunately VB6 and I am not the original programmer. The values are being passed to a function that sets up a stored procedure....
The initial function looks something like this: -
Public Function RunSP(InputParam1, InputParam2, etc...)
-
'All the magic that is not currently working
-
end function
-
I need to go through the above InputParams and put them into something like this: -
cmd.Parameters(iCount).value = InputParam & ICount
-
Does that make any better sense? :)
On the "Public Function RunSP..." line, do any of the InputParams have a type after them?
For example: InputParam1 As String
OR InputParam1 As Long
Usually there is some form of type that is assigned to each parameter in a function. If there isn't, it certainly makes it more difficult to determine which types of variables should be sent to the function as parameters.
We would need to get a good look at the rest of the function to get a better understanding of how it works.
Param1 and Param2 are strings and the rest are optional.
Then I presume that the function looks more like this: Example: -
Public Function RunSP (InputParam1 As String, InputParam2 As String, Optional Var1...)
-
If the rest of the parameters have the optional keyword next to them, then you obviously don't need to give them to the function.
Since the first two parameters are apparently of the "string" type, you need to send two string variables to the function, like this: Example: -
RunSP MyStrVar1, MyStrVar2
-
*Note: You can call the string variables whatever you want.
If the function has a "return value" (i.e. there is a line in the function itself somewhere that looks like this); Example:
then the line with which you call the function needs to begin with a variable that stores the return value, like this: Example: -
I = RunSP(MyStrVar1, MyStrVar2)
-
The variable that you use to store the return value must match (or be very much like) the return value's type.
I take it that you are using VB.NET?
Then I presume that the function looks more like this: Example: -
Public Function RunSP (InputParam1 As String, InputParam2 As String, Optional Var1...)
-
If the rest of the parameters have the optional keyword next to them, then you obviously don't need to give them to the function.
Since the first two parameters are apparently of the "string" type, you need to send two string variables to the function, like this: Example: -
RunSP MyStrVar1, MyStrVar2
-
*Note: You can call the string variables whatever you want.
If the function has a "return value" (i.e. there is a line in the function itself somewhere that looks like this); Example:
then the line with which you call the function needs to begin with a variable that stores the return value, like this: Example: -
I = RunSP(MyStrVar1, MyStrVar2)
-
The variable that you use to store the return value must match (or be very much like) the return value's type.
I take it that you are using VB.NET?
No, I am using VB6. Yes, I definitely need to give the optional strings to the function.
Your first post mentions a "ToString" method.
I don't believe that this exists in VB6, which led me to believe that you were using VB.NET, or at least the code that you were trying to use came from a VB.NET progam.
We could probably solve this problem a lot quicker if you: A: Provided us with the bulk of the code that you are trying to use (or all of it if you are not sure) B: Told us exactly what it is that you are trying to progam.
My bad on the toString part... I typed it out instead of copying it over and am just used to writing in .Net these days.
Here is the idea of how things are currently working:
1. The initial function that is being called: -
RunSP "StoredProcName", StringVal1, StringVal2, optional1, optional2, etc
-
There can be up to 50 optional values at this point.
2. Gets to the Main.bas file -
Public Function RunSP(StoredProc as string, StringVal as String, StringVal as String, InputParam1 as optional, InputParam2 as optional, ..., InputParam50 as optional)
-
'This is what I would rather loop through instead of typing out the way I have it now. My initial post has an example of how I was trying to do it... Minus the .tostring part.
-
-
If IsMissing(InputParam1 = false then
-
cmd.Parameters(1).Value = InputParam1
-
-
If IsMissing(InputParam2 = false then
-
cmd.Parameters(2).Value = InputParam2
-
-
' Through
-
-
If IsMissing(InputParam50) = false then
-
cmd.Parameters(50).Value = InputParam50
-
-
end Function
-
If InputParam1 = "Hello World" then "InputParam" & 1 should also equal the same value so that I can do something like this; -
for Count = 1 to 50
-
strTemp = "InputParam" & cstr(Count)
-
If IsMissing(strTemp) = false then
-
cmd.Parameters(Count).Value = strTemp
-
Let me know if something does not make sense. Thanks.
Anyone have any more ideas of how to do this? Or if it is even possible?
Sorry I didn't get back to you quicker; I've been fairly busy over the last few days.
Have you tried giving an array to the function, and then looping through the array within the function? Using this approach would be much better than the existing one.
Reply again if you are not sure, and I'll try to provide you with some sample code.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nasos Makriyiannis |
last post by:
Hi,
I'm new to XSL and I was wondering if there is a string-compare function
available. I am using the following IF statement but it does not seem to be
working:
<xsl:if...
|
by: Sebek |
last post by:
Hello,
I'm transforming a XML document in XHTML but I have problems using
sub-strings, it will be clearer with an exemple:
What I have:
<form...
|
by: shaun roe |
last post by:
I have an xml format for creating a database; lets say a fragment looks
like this:
<insertValue type="int">7</insert>
<insertValue type="string">Hello everyone</insert>
now I have a...
|
by: glenn |
last post by:
Hi folks,
The problem I have is that a query string works if hard-coded but
if I pass a variable to it, it does not work as shown here.
This works:
querystring="SELECT * FROM USERS WHERE...
|
by: TheLostLeaf |
last post by:
Hello,
I am trying to get this code:
p1_1.Image = System.Drawing.Bitmap.FromFile(imgPath +
picture.ToString() + ".GIF");
p2_1.Image = System.Drawing.Bitmap.FromFile(imgPath +...
|
by: Bilal |
last post by:
Hello,
I'm trying to perform some string manipulations in my stylesheet and
have gotten stuck on the issue below so hopefully can elicit some useful
hints.
Namely, the problem is that I need to...
|
by: Jean-François Michaud |
last post by:
Hello,
I've been looking at this for a bit now and I don't see what's wrong
with the code. Can anybody see a problem with this?
Here is an XSLT snippet I use.
<xsl:template match="graphic">...
|
by: Jennifer.Berube |
last post by:
well I'm not sure how to go about making my SQL connection string...
The code below is what I need to replace with my SQL connection...I
just don't know if that code is for DSN or access...
I...
|
by: Hvid Hat |
last post by:
Hi
I want to highlight (make it bold) a word in some text I'm getting in XML
format. My plan was to replace the word with a bold (or span) tag with the
word within the tag. I've found the code...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |