-
Help: Upload dll with multiple Select list
This site is the best one for vb newbie like me!
I am writing one upload dll simlar functions to aspSmartUpload component, (of course, I get a lot of code and help from this site!).
I made the upload and download functions working, but then I found I have problem to display form variables for miltiple select list, since it is same name with mulitple values.
I use form collection to collect all the form variables, when I parse the raw data to get name and value. I look for some advice/guide on this.
Thanks in advance.
-
Please help!
The following is what I try to do.
'Get the FormFieldName
strFormFieldName = MidB(varHTTPHeader, lngFormFieldNameStart + Len(StrConv("; name=" & Chr(34), vbUnicode)), (lngFormFieldNameEnd - Len(StrConv(Chr(34), vbUnicode))) - (lngFormFieldNameStart + Len(StrConv("; name=" & Chr(34), vbUnicode))))
'Filter formfieldvalue
strFormFieldValue = MidB(varHTTPHeader, lngFormFieldValueStart, lngFormFieldValueEnd - lngFormFieldValueStart)
If IsEmpty(c_FormItems.Item(strFormFieldName)) Then
c_FormItems.Add strFormFieldValue, strFormFieldName
Else
Dim cValue As String
cValue = c_FormItems.Item(strFormFieldName)
'remove the item, can I modify?
c_FormItems.Remove (strFormFieldName)
cValue = cValue & "," & strFormFieldValue
c_FormItems.Add cValue, strFormFieldName
End If
so if I have "option1" and "option2" both selected, I can have value as "option1,option2" returned just like request.form("select").
Update: I always get the error saying: Invalid procedure or argument.
and I thought I could use c_FormItems.Add (strFormFieldValue,strFormFieldName), but it gave me compile error, I have to change to c_FormItems.Add strFormFieldValue,strFormFieldName, it let me compile, but give the above error.
Please help!
Last edited by vbdll; 01-12-2007 at 03:31 PM.
Reason: Update for help
-
Please help!
How do I check if item exists in collection and then modify the item?
I look all over in MSDN, and alwway get error about Invalid procedure call or argument.
-
well in vb u can't put brackets if u havent a return to a variable ..
I mean this is ok : " a=function(arg1,arg2) " which will execute the function then put the return value in a, but this is not accepted : function(arg1,arg2) however if the function haven't a return value ,, u must not put bracktes here ..
the nearest example is the MsgBox() function .
about your error I think you have problem with the function call , check this :
-what is c_FormItems?
-does it have a member function ".add" ?
-does it take two parameters only ?
-u pass it a valid argument ? I mean if the arg1 is form , u must pass a form and so on ...
-
Thanks for the reply.
c_FormItems is a collection, the Add is the default method, which supposed to be .add (value, key), but I get complie error, so I use .add value, key.
Dim c_FormItems As Collection
OnStartPage()
Set c_FormItems = New Collection
When I do strTry = c_FormItems(strFormFieldName), it complian about this retieve.
Dim strTry As String
'On Error Resume Next
strTry = c_FormItems(strFormFieldName)
Here is the code:
PHP Code:
(sorry, just use the php tag, it's vb code of course)
If the field is a file, add into fileitems collection
Else
'Determine where filedata begins
lngFormFieldValueStart = InStrB(lngFormFieldNameEnd, varHTTPHeader, vbCrLf & vbCrLf) + Len(StrConv(vbCrLf & vbCrLf, vbUnicode))
'Determine where filedata ends
lngFormFieldValueEnd = InStrB(lngFormFieldValueStart, varHTTPHeader, vbCrLf & varDelimeter)
'Filter formfieldvalue
strFormFieldValue = MidB(varHTTPHeader, lngFormFieldValueStart, lngFormFieldValueEnd - lngFormFieldValueStart)
'we will search for next field from here...
lngFormFieldNameStart = lngFormFieldValueEnd
'save the fields value
strDebug = strFormFieldValue & strFormFieldName
Dim strTry As String
'On Error Resume Next
'strTry = c_FormItems(strFormFieldName)
strTry = strFormFieldName
If Len(strTry) > 0 Then
strDebug = "multiple"
Else
strDebug = "single"
'c_FormItems.Add strFormFieldValue, strFormFieldName
End If
c_FormItems.Add strFormFieldValue, strFormFieldName
End If
If I comment out the 'strTry = c_FormItems(strFormFieldName), I dont receive the Invalid procedure call or argument.
Thanks again for your help.
Last edited by vbdll; 01-12-2007 at 04:32 PM.
-
In this collection u must put an integer that points to the index of the selected item ,
I guess that "strFormFieldName" is a string not a long .. so u want to assigne what ? u must specify the index in this collection which contains this string variable and put it into those brackets .
Last edited by Amahdy; 01-12-2007 at 05:02 PM.
-
*ps u can use [ code ] tag .. it hasn't a colourful interface but it adjust spaces .
-
 Originally Posted by Amahdy
In this collection u must put an integer that points to the index of the selected item ,
I guess that "strFormFieldName" is a string not a long .. so u want to assigne what ? u must specify the index of this collection which contains this string variable and but it into those brackets .
I thought you dont have to use index, instead use key.
http://msdn2.microsoft.com/en-us/lib...e5(VS.80).aspx
So how should I retrieve the value and modify, basiclly I want to:
I have form name and value parsed from raw data, let says mulitple list named cblist with 2 values (option1, and option2).
So I get the first set, cblist->option1, and I add to collection key is cblist, value is option1, then next parse I got cblist->option2, I want to modify my cblist's value to "option1,option2".
That's what I come from, check if the item (cblist) has a value already, if it has, modify it.
Hope I made it clear what I mean.
-
No this is different , the index of the item is different from the "Optional" key of the item .. u have used this : object(string) which is must be object(index_of_type_long)
in the other side in the add method u can do that :
object.add(item, key_string) OR object.add(item)
well returning back to your original code , which gives u invalid call , maybe because the key is not "unique" ? do u use it for different items or in a loop for example ?
I'm talking about this :"strFormFieldName" maybe it's empty ? or maybe the item itself is not defined ?
-
 Originally Posted by Amahdy
well returning back to your original code , which gives u invalid call , maybe because the key is not "unique" ? do u use it for different items or in a loop for example ?
I'm talking about this :"strFormFieldName" maybe it's empty ? or maybe the item itself is not defined ?
You are great! I do have some loop which gave me some grief, I dare not to post all code (kind of long and messy), but I will look more carefully to see if I could find the problem.
-
U r mostly welcome Mr. ActivX [I liked your nickname ]
-
I still could not find the problem, I use index or even hardcode,like this:
Dim x As Variant
x = c_FormItems.Item("cblist1")
or
x = c_FormItems.Item(1)
still give me the error. I found someone's post, It works if for a collection of strings, but I can not find what I did wrong!
http://www.experts-exchange.com/Prog..._21736095.html
Code:
Public Function existInColl(tmpCollection As Collection, key As String) As Boolean
Dim x As Variant
On Error Resume Next
x = tmpCollection.item(key)
If IsEmpty(x) Or x = "" Then
existInColl = False
Else
existInColl = True
End If
On Error GoTo 0
End Function
my head is spinning, sigh...
-
I think this guy is wrong it must be :
x = tmpCollection.item(INDEX)
your error here:
x = c_FormItems.Item(1)
maybe you haven't the item 1 ? u must first add the item 1 to be able to get it by your method ..
remember : a collection is 1 based but arrays in collection are zero based :
c_FormItems(One_Based)
c_FormItems.xyz(zero_bazed)
-
###I'm sorry I gived u wrong info, all sub arrays from collection are one based too ;
try this :
Code:
Dim a As Collection
Set a = New Collection
a.Add ("string")
MsgBox a.Item(1)
-
###I'm sorry again but I gived u wrong info again, in collections u can call items by their key ...
try this :
Code:
Dim a As Collection
Set a = New Collection
a.Add "string", "alpha"
MsgBox a.Item("alpha")
I had a confusion with something else but now it's ok isa .
Similar Threads
-
By lotu4 in forum VB Classic
Replies: 0
Last Post: 10-18-2006, 11:19 PM
-
By Beryn in forum VB Classic
Replies: 0
Last Post: 09-19-2006, 06:08 PM
-
By Larry Rebich in forum vb.announcements
Replies: 1
Last Post: 06-28-2001, 01:22 PM
-
By malikmehmood in forum Database
Replies: 0
Last Post: 11-20-2000, 05:12 AM
-
Replies: 1
Last Post: 09-17-2000, 08:44 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks