Hi,
I am getting a string passed back from a web form in the format
name1:variable1;name2:variable2...
I would like to split this up into several variable, such that the variable
names are name1, name2 etc. (I actually know what these names are) and the
values of the variables are variable1, variable2 etc.
I tried using split to split the string into an array at the semicolons, and
was then thinking I would split the value out with a second split command,
but this seems a bit of a complex way round the problem. Also I am having
some problems with the implementation.
My two questions are:
1. What is wrong with the code as it stands
2. What better way is there of acheiving the desired effect
My VB.NET code behind is something like:
'Declare Variables
Dim DataString As String
Dim DataArray(9) As String
'Get Data from http
DataString = Request("DataString")
'Parse Data
DataArray = TimeEntryData.Split(CChar(";")) 'This is the line that gives an
error
name1=TimeEntryDataArray(1)
Response.Write(name1)
And the Error I get is:
Object reference not set to an instance of an object.
Thanks,
Martin 10 1340
In your code, what is TimeEntryData?
You seem to want to split 'DataString'
You should have DataArray = DataString.Split( CChar(";"))
"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message
news:11*************@corp.supernews.com... Hi,
I am getting a string passed back from a web form in the format name1:variable1;name2:variable2...
I would like to split this up into several variable, such that the variable names are name1, name2 etc. (I actually know what these names are) and the values of the variables are variable1, variable2 etc.
I tried using split to split the string into an array at the semicolons, and was then thinking I would split the value out with a second split command, but this seems a bit of a complex way round the problem. Also I am having some problems with the implementation.
My two questions are: 1. What is wrong with the code as it stands 2. What better way is there of acheiving the desired effect
My VB.NET code behind is something like: 'Declare Variables Dim DataString As String Dim DataArray(9) As String 'Get Data from http DataString = Request("DataString") 'Parse Data DataArray = TimeEntryData.Split(CChar(";")) 'This is the line that gives an error name1=TimeEntryDataArray(1) Response.Write(name1)
And the Error I get is: Object reference not set to an instance of an object.
Thanks, Martin
"Phillip N Rounds" <pr*****@cassandragroup.com> wrote in message
news:ui**************@TK2MSFTNGP10.phx.gbl... In your code, what is TimeEntryData? You seem to want to split 'DataString' You should have DataArray = DataString.Split( CChar(";"))
Sorry, didn't finish renaming the variables for general-ness. The code
should read:
'Declare Variables
Dim DataString As String
Dim DataArray(9) As String
'Get Data from http
DataString = Request("DataString")
'Parse Data
DataArray = DataString.Split(CChar(";")) 'This is the line that gives an
error
name1=DataArray(1)
Response.Write(name1)
Martin,
I think using the split function is a fine way to get your values. I'm not
aware of a better way. But perhaps someone else may chime in here on that.
That said here's a small example:
Dim TestData As String = "9;8;7;6;5;4;3;2;1;0"
Dim Data() As String = TestData.Split(CChar(";"))
Dim Value As String
For Each Test As String In Data
Value = Test
Next
Note that I'm not pre-defining the array.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message
news:11*************@corp.supernews.com... Hi,
I am getting a string passed back from a web form in the format name1:variable1;name2:variable2...
I would like to split this up into several variable, such that the variable names are name1, name2 etc. (I actually know what these names are) and the values of the variables are variable1, variable2 etc.
I tried using split to split the string into an array at the semicolons, and was then thinking I would split the value out with a second split command, but this seems a bit of a complex way round the problem. Also I am having some problems with the implementation.
My two questions are: 1. What is wrong with the code as it stands 2. What better way is there of acheiving the desired effect
My VB.NET code behind is something like: 'Declare Variables Dim DataString As String Dim DataArray(9) As String 'Get Data from http DataString = Request("DataString") 'Parse Data DataArray = TimeEntryData.Split(CChar(";")) 'This is the line that gives an error name1=TimeEntryDataArray(1) Response.Write(name1)
And the Error I get is: Object reference not set to an instance of an object.
Thanks, Martin
"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message
news:11*************@corp.supernews.com... Hi,
I am getting a string passed back from a web form in the format name1:variable1;name2:variable2...
I would like to split this up into several variable, such that the variable names are name1, name2 etc. (I actually know what these names are) and the values of the variables are variable1, variable2 etc.
I tried using split to split the string into an array at the semicolons, and was then thinking I would split the value out with a second split command, but this seems a bit of a complex way round the problem. Also I am having some problems with the implementation.
My two questions are: 1. What is wrong with the code as it stands 2. What better way is there of acheiving the desired effect
My VB.NET code behind is something like: 'Declare Variables Dim DataString As String Dim DataArray(9) As String 'Get Data from http DataString = Request("DataString") 'Parse Data DataArray = TimeEntryData.Split(CChar(";")) 'This is the line that gives an error name1=TimeEntryDataArray(1) Response.Write(name1)
And the Error I get is: Object reference not set to an instance of an object.
Thanks, Martin
Hrm...for something like this, I would use regular expressions...
Example:
Dim input As String = "name1=value1;name2=value2;name3=value3;"
Dim pattern As String = _
"(?<Name>[^=;]*)=(?<Value>[^=;]*);"
Dim matchCollection As MatchCollection = Regex.Matches(input, pattern)
For Each match As Match In matchCollection
Console.WriteLine( _
"Name: {0} - Value: {1}", _
match.Groups("Name").Value, _
match.Groups("Value").Value _
)
Next match
HTH,
Mythran
On Thu, 12 Jan 2006 16:06:40 +0000, Martin Eyles wrote: Hi,
I am getting a string passed back from a web form in the format name1:variable1;name2:variable2...
I would like to split this up into several variable, such that the variable names are name1, name2 etc. (I actually know what these names are) and the values of the variables are variable1, variable2 etc.
I tried using split to split the string into an array at the semicolons, and was then thinking I would split the value out with a second split command, but this seems a bit of a complex way round the problem. Also I am having some problems with the implementation.
My two questions are: 1. What is wrong with the code as it stands 2. What better way is there of acheiving the desired effect
My VB.NET code behind is something like: 'Declare Variables Dim DataString As String Dim DataArray(9) As String 'Get Data from http DataString = Request("DataString") 'Parse Data DataArray = TimeEntryData.Split(CChar(";")) 'This is the line that gives an error name1=TimeEntryDataArray(1) Response.Write(name1)
And the Error I get is: Object reference not set to an instance of an object.
Thanks, Martin
Looks like you are transmitting a JavaScript object literal. This protocol
has been named JSON. You may find in open source forums code to split this
effectively. Note that is similar to splitting a name/value string (as
Form or QueryString have); so code in CPAN for doing this can also be
found there.
Now, since you already have some sort of Javascript object literal, why
don't you use JSscript to decode this? First enclose the hole thin in {},
then change your ':' to ":\'" and your ',' to, you get the idea. Then
instantiate the object in JScript and there you have it all nicely
separated.
"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:%2****************@TK2MSFTNGP15.phx.gbl... Martin,
Dim Data() As String = TestData.Split(CChar(";"))
Note that I'm not pre-defining the array.
"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message news:11*************@corp.supernews.com... 1. What is wrong with the code as it stands
And the Error I get is: Object reference not set to an instance of an object.
Even not pre-defining the array, I still get the same error. Any idea why?
Thanks,
Martin
"intrader" <in******@aol.com> wrote in message
news:pa****************************@aol.com... On Thu, 12 Jan 2006 16:06:40 +0000, Martin Eyles wrote:
Looks like you are transmitting a JavaScript object literal. This protocol has been named JSON. You may find in open source forums code to split this effectively. Note that is similar to splitting a name/value string (as Form or QueryString have); so code in CPAN for doing this can also be found there. Now, since you already have some sort of Javascript object literal, why don't you use JSscript to decode this? First enclose the hole thin in {}, then change your ':' to ":\'" and your ',' to, you get the idea. Then instantiate the object in JScript and there you have it all nicely separated.
I think you have mis-understood what I am trying to do.
What is happening is that the user fills in a form in a pop-up window.
Javascript on the client side makes the string, and passes it from a pop-up
to a hidden input in the main window's form. The main window then closes the
pop-up and performs a post-back. Finally, the VB.net code on the server
decodes the string, and uses it as input to an SQL query, returning the
results with the posted page.
I think that the other answers are already covering what I am looking for on
this, but thanks for the info anyway,
Martin
"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message
news:11*************@corp.supernews.com... "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl... Martin,
Dim Data() As String = TestData.Split(CChar(";"))
Note that I'm not pre-defining the array.
"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message news:11*************@corp.supernews.com... 1. What is wrong with the code as it stands
And the Error I get is: Object reference not set to an instance of an object.
Even not pre-defining the array, I still get the same error. Any idea why?
Thanks, Martin
Found a potential source of the problem - the string is empty. But I am
confused, it should have all the data. I have tried both
Data = Request("Data")
and
Data = Request("Menu1_Data")
but both of these leave Data entirely empty. (note, Data is the name in the
menu.ascx file, but Menu1_Data is the name that appears on the page itself).
Thanks,
Martin
Martin,
It wasn't until I read your reply to intrader that I realized I have an
example you may be able to use.
In the code library on my website: http://www.aboutfortunate.com?page=codelibrary do a search for "close pop-up
and refresh" I have some example code for closing a pop-up window and
refreshing the main one and also calling code. It may help you get those
values back. I think I'm using a different technique than you, but it may
work for you.
Using the technique you'll find you can actually run your code within the
pop-up's page and then close it.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message
news:11*************@corp.supernews.com... "Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message news:11*************@corp.supernews.com... "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl... Martin,
Dim Data() As String = TestData.Split(CChar(";"))
Note that I'm not pre-defining the array.
"Martin Eyles" <ma**********@NOSPAMbytronic.com> wrote in message news:11*************@corp.supernews.com... 1. What is wrong with the code as it stands
And the Error I get is: Object reference not set to an instance of an object.
Even not pre-defining the array, I still get the same error. Any idea why?
Thanks, Martin
Found a potential source of the problem - the string is empty. But I am confused, it should have all the data. I have tried both
Data = Request("Data") and Data = Request("Menu1_Data")
but both of these leave Data entirely empty. (note, Data is the name in the menu.ascx file, but Menu1_Data is the name that appears on the page itself).
Thanks, Martin
"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:ep*************@TK2MSFTNGP11.phx.gbl... Martin,
It wasn't until I read your reply to intrader that I realized I have an example you may be able to use.
In the code library on my website: http://www.aboutfortunate.com?page=codelibrary do a search for "close pop-up and refresh" I have some example code for closing a pop-up window and refreshing the main one and also calling code. It may help you get those values back. I think I'm using a different technique than you, but it may work for you.
Using the technique you'll find you can actually run your code within the pop-up's page and then close it.
Thanks for the example. I don't think it does quite what I want (send data
back to the server), but that is OK, as I have solved the problem. I can in
fact use the fact that the form is server side, so rather than having to use
request, I can just use the variable name, and the language recognises it as
already declared. Thanks Anyway.
Martin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: |
last post by:
Hi,
I need to read a big CSV file, where different fields should be converted to
different types,
such as int, double, datetime, SqlMoney, etc.
I have an array, which describes the fields and...
|
by: Jon Davis |
last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST"
The problem:
// this fails on PST
DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST");
Help?
Jon
|
by: Mark |
last post by:
How do you parse a currency string to a decimal? I'd like to avoid having
to parse the number out, removing the $ manually. That sounds like a hack.
There are times that this string will be...
|
by: Jon Davis |
last post by:
I have put my users through so much crap with this bug it is an absolute
shame.
I have a product that reads/writes RSS 2.0 documents, among other things.
The RSS 2.0 spec mandates an en-US style...
|
by: Bob Rundle |
last post by:
I would like to get something like this to work...
Type t = FindMyType(); // might be int, float, double, etc
string s = "1233";
object v = t.Parse(s);
This doesn't work of couse, Parse is...
|
by: Slonocode |
last post by:
I have some textboxes bound to an access db. I wanted to format the
textboxes that displayed currency and date info so I did the following:
Dim WithEvents oBidAmt As Binding
oBidAmt = New...
|
by: BWIGLEY |
last post by:
Basically I've just started making a game. So far it makes an array
25 by 20 and tries to make five rooms within it.
In scr_make_room() there's parse errors:
20 C:\c\Rooms\Untitled1.c parse error...
|
by: js |
last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss".
I need to parse the text using System.DateTime.Parse() function with
custom format. I got an error using the following code. ...
|
by: Samuel R. Neff |
last post by:
I'm using a quasi open-source project and am running into an exception
in double.Parse which is effectively this:
double.Parse(double.MinValue.ToString())
System.OverflowException: Value was...
|
by: Peter Duniho |
last post by:
I'm sure there's a good explanation for this, but I can't figure it out.
I tried using DateTime.Parse() with a custom DateTimeFormatInfo instance,
in which I'd replaced the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |