'Here is some of the code I have so far.
Dim Contacts(25, 4) As String
This is where I add to the listbox
Private Sub btnAddToList_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnAddToList.Cl ick
Dim f, l As Integer
f = Len(txtFirstNam e.Text)
l = Len(txtLastName .Text)
'print to listbox in columns
lstList.Items.A dd(txtLastName. Text & Space(30 - l) & _
txtFirstName.Te xt & Space(26 - f) & _
txtPhone.Text)
'put into an array
Contacts(lstLis t.Items.Count - 1, 0) = txtLastName.Tex t
Contacts(lstLis t.Items.Count - 1, 1) = txtFirstName.Te xt
Contacts(lstLis t.Items.Count - 1, 2) = txtPhone.Text
Contacts(lstLis t.Items.Count - 1, 3) = txtCatagory.Tex t
'clear the fields for new values
txtFirstName.Te xt = ""
txtLastName.Tex t = ""
txtPhone.Text = ""
txtCatagory.Tex t = ""
txtFirstName.Fo cus()
Private Sub btnDisplay_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnDisplay.Clic k
'clear the listbox
lstList.Items.C lear()
'try to print one item to the listbox from the array named Contacts
lstList.Items.A dd(Contacts(lst List.Items.Coun t - 1, 0))
'here is the error message I get??? An unhandled exception of type 'System.IndexOu tOfRangeExcepti on' occurred in ListProgram.exe
Additional information: Index was outside the bounds of the array.
What do I have wrong here???
Thanks
Gary
3 3995
wow.. took me a second. ok, i would need to see more code by ive got my hunch:
<problem>
lets say, perhaps, that your lstlist is empty, right, and you run your code. im assuming it would be empty to start since you are running your program to fill it
Contacts(lstLis t.Items.Count - 1, 0) = txtLastName.Tex t
Contacts(lstLis t.Items.Count - 1, 1) = txtFirstName.Te xt
Contacts(lstLis t.Items.Count - 1, 2) = txtPhone.Text
Contacts(lstLis t.Items.Count - 1, 3) = txtCatagory.Tex t
if your list is empty then it is trying to fill the array contacts(-1,0). array values are positive, i think you have it defined 0 to 24 and -1 is not in that.
<fix>
i think you should have made this +1 instead of -1. but again, i dont know your application.
a round about way to fix this is to have the program add a null list entry to the listbox when it starts.
and... i could just be completely wrong.
-bsob
This is where I am loading the array with values from LastName, FirstName, Phone and Catagory.
Contacts(lstLis t.Items.Count - 1, 0) = txtLastName.Tex t
Contacts(lstLis t.Items.Count - 1, 1) = txtFirstName.Te xt
Contacts(lstLis t.Items.Count - 1, 2) = txtPhone.Text
Contacts(lstLis t.Items.Count - 1, 3) = txtCatagory.Tex t
I tryed +1 instead of -1 same thing happened.
Thanks
Gary
next suggestion, instead of a -1 or +1, leave out that bit entirely. Have contacts(lstlis t.items.count, 0) = txtlastname.tex t.
this will still give an error if lstlistitems.co unt is more than 24. and i dont know what your list has in it when you run this subroutine. check that out.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Kathryn |
last post by:
Hiya
I have a problem with using some client side and server side scripting
together in an ASP. I'm using VBScript.
What I'm trying to achieve is this -
- Page loads up and some server side vbscript reads the database and
populates a listbox on the page with the first field from each record
in the recordset. This works fine.
- User selects an option on the listbox and, using the OnChange, I
|
by: Arif |
last post by:
I C# code prints very slow as compared to a third party barcode printing
software. That software prints approximately 10 labels in 2 seconds while my
C# code prints 10 labels in 5 to 6 seconds. And this differences increases
with the increase number of labels.
The code is as follwods:
Here rdr = OleDbDataReader
Font is Times New Roman, 12pt
|
by: 00_ChInkPoIntD12 |
last post by:
Can anyone confirm there isn't a Sort() method for WebControl Listbox in
Asp.net?
It is rather simple to write a method to do the sorting, but just wondering
I shouldn't invent the wheel if there is already one.
C.P.
|
by: hardik |
last post by:
hi friends
i am very new to java script.if anyone can help me out then
i will be thankful.
i am using php and mysql in my learning project and i have
two list boxes,now whenever user presses first listbox i mean user
selects listbox then approprieate records should be come in second
listbox.can i do it with javascript? i.e if user selects list item
'class bca' then all the records related to 'class bca' should come to
|
by: Sunray |
last post by:
I have a form called the sales form and i have 2 sets of listboxes
So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set.
when i tried to use a remove item code it worked fine, it did delete the item form the list but it added...
| |
by: Iain Wilson |
last post by:
I am pulling my hair out trying to print various objects from a .net
web page
My apologies for cross posting but I need an answer and my previous
post has attracted no interest.
ASP.Net 2.0 using C#
This is a simple web page on our intranet (written as a test) and all
I am trying to do is print a document to a named printer.
If I use a StreamReader then I get an output to the printer. This
|
by: dotnet2005 |
last post by:
Hi Toall ,
I want to explain you clearly ,
I am having some panels having some controls
CheckBox,ComboBox,Datagridview,Hyperlink,label,Listbox,Picturebox,RadioButt
on ,Textbox)
&(Oval,Line,Rectangle ). with .BorderStyle =
BorderStyle.FixedSingle . All these things are generating at runtime
|
by: Iain Wilson |
last post by:
I am pulling my hair out trying to print various objects from a .net
web page
My apologies for cross posting but I need an answer and my previous
post has attracted no interest.
ASP.Net 2.0 using C#
This is a simple web page on our intranet (written as a test) and all
I am trying to do is print a document to a named printer.
If I use a StreamReader then I get an output to the printer. This
|
by: Sweetiecakes |
last post by:
Hi
I have an string array containing file paths. I have added them to a
ListBox with AddRange();
When I delete an item from the ListBox, how can I delete the same item
from the original array?
Thanks
|
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,...
|
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...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |