473,804 Members | 4,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb2005 + -1 Dimensional String error

79 New Member
Hi,

I pretty new to VB2005 i was just working on a project a problem arise which really got me frustrated.

Dim searchThese(1) As String
myvar(0) = "Hi"
myvar(1) = "Bye"

searchfolder(my var as string)

after defining the above array i was making a function like this:

Function SearchFolder(By Val myvar As String())
// code here
End Function

when i run the above could i get an error saying "Value of '-1 Dimensional array of string' cannot be converted to string"

i am really confused on why this is happening and how i can resolve this problem any help would be highly appreciated.

Regards
Sep 17 '08 #1
10 1185
zubair1
79 New Member
Bump :(

Any help please :(
Sep 17 '08 #2
PRR
750 Recognized Expert Contributor
string[] ss=new string[1];
// here the size is one ; so you can only have ss[0] and not ss[1];
for that string[] ss=new string[2];
Sep 17 '08 #3
zubair1
79 New Member
Hello,

Thanks for your response DirtBag :)

i'm sorry :( but i still cant understand :( sorry n00b here :)

I started an array as
dim var as string(1)

so does that mean i only have one index?

i'm not quite sure, does the index of an array start from 0 or 1 in vb.net?

could you point out exactly how i can fix my code that presented :(

Thanks in advance :)
Regards
Sep 17 '08 #4
Plater
7,872 Recognized Expert Expert
dim var as string(1)
Would mean that there is only one element in your string array.
Sep 17 '08 #5
zubair1
79 New Member
:(

sorry but I'm still confused :(

okay, can you just give me a small code

I have 3 checkboxes on my form

chkBox1 to chkBox 3

what i am trying to accomplish is that i check chkbox1 to see if it is checked.

if its checked i want to add a value to an array (myVar)

i try to do it like this

dim myVar(1) as string

IF chkBox1.checked = true then
myVar() = "Johnny Bravo"
End If

IF chkBox2.checked = true then
myVar() = "Hulk Hogan"
End If

i cant see what is wrong i'm sure its something with myVar()= part but i am not sure - i sort of want this array to be dynamic because i will not have 3 checkboxes i will have about 10 and i only want to insert values for only those which have been Checked.

Please can some one give me a working code for this :(

Thanks for the prompt response guys :)
Sep 17 '08 #6
cloud255
427 Recognized Expert Contributor
An array cannot be addressed like a variable:

myVar() = whatever

is wrong.

you need to supply an index within the array:

myVar(0) = whatever.

I suggest you look at this

or get a text book to help you understand further
Sep 17 '08 #7
zubair1
79 New Member
Thanks

i got that..

but can you tell me howto do what i'm trying to accomplish in my last post please

Thanks

Regards,
Sep 17 '08 #8
Curtis Rutland
3,256 Recognized Expert Specialist
If you need a dynamically sized array, you should use a List.

Expand|Select|Wrap|Line Numbers
  1. Dim l As New Generic.List(Of String)
  2. l.Add("string 1")
  3. l.Add("string 2")
  4. Dim s As New String
  5. For Each s In l
  6.   Console.WriteLine(s)
  7. Next
  8.  
You can also access each element like you could an array.
Sep 17 '08 #9
zubair1
79 New Member
If you need a dynamically sized array, you should use a List.

Expand|Select|Wrap|Line Numbers
  1. Dim l As New Generic.List(Of String)
  2. l.Add("string 1")
  3. l.Add("string 2")
  4. Dim s As New String
  5. For Each s In l
  6.   Console.WriteLine(s)
  7. Next
  8.  
You can also access each element like you could an array.
Sir, you are too good :)

SUPER HELP! :)

Thanks - i can't tell you how easy it made my work after using your method of List()

Thank you so much :)

Kind Regards,
Sep 17 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2790
by: Venkat | last post by:
Hi All, I need to copy strings from a single dimensional array to a double dimensional array. Here is my program. #include <stdio.h> #include <stdlib.h>
4
7590
by: cql60 | last post by:
Hi all Pro, I have the class call "Person", and I do declare two dimensional array type of string inside this class which will keep "First_Name" and "Last_Name" as the record. When I try to serialize it by using XMLSerializer, I got error like this: An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll Additional information: There was an error reflecting type
6
2698
by: Ruben | last post by:
I'm trying to pass an array of string to a function without knowing how many strings I have beforehand. I've defined one functions as char * insert(char table,int cols, char values); out of deperation because when I defined it as char * insert(char table,int cols, char values)
10
4396
by: Charles Hunt | last post by:
Hi, When running this code in VB2003 Sub guidtest() Dim gstring As String Dim gid As Guid
1
1778
by: Galen Somerville | last post by:
And yet another VB6 to VB2005 problem. All helpful suggestions appreciated. As you can see in the code below, my structures use fixed length strings and known array sizes. Consequently I can save to files as a large byte array. This is a series of Lectures where there is a capacity for 8 instructors with up to 8 lectures each. So a parameters file made from glctInstTable is 2,232 bytes. The 64 lectures, for the above, each consist of...
6
2280
by: fniles | last post by:
I need to store information in a 2 dimensional array. I understand ArrayList only works for a single dimensional array, is that correct ? So, I use the 2 dimensional array like in VB6. I pass the array into a subroutine, and inside it I "Redim Preserve" the array to increase the number of item in the array. I got the error "Redim statement requires an array", but arr is an array. HOw can I fix this problem ? Or, how can I do ArrayList for...
92
3359
by: =?Utf-8?B?bW9iaWxlbW9iaWxl?= | last post by:
I'm trying to load this structure for a call to DeviceIoControl: typedef struct _NDISUIO_QUERY_OID { NDIS_OID Oid; PTCHAR ptcDeviceName; UCHAR Data; } NDISUIO_QUERY_OID, *PNDISUIO_QUERY_OID; I created the equivalent in VB:
15
2031
by: Aalaan | last post by:
I am presently a user of classic vb6 and hang out on those newsgroups. Some of you may be aware that there is a very anti MS and vb2005 feeling there. I have tried to get them to tell me which features of vb2005 are actually worse then vb6 in practice, and forget the philosophy of backward compatibility for a moment. I would now like to hear "the other side". Could *anyone who previously used vb6* (only those pleased; I feel the others...
0
1354
by: Rik Moed | last post by:
Hi all, I encounter a problem with a library method that should create a multi dimensional string array. Below is the method: -------------------------------------------------------------------------------- public class StringArrayLibrary { public void Create(ref string names)
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7616
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.