473,322 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Interesting situation

One thing I'vew come to dislike is .NEt's lack of sensable error messages. On this one, I get an "Index out of bounds" Can't figure it out. Will give ya the setup...

Protected Structure Letter
Dim Series1 As String
Dim Series2 As String
Dim Series3 As String
End Structure

Dim StoreLetter As Letter

StoreLetter = New Letter()
StoreLetter.Series1 = 0

If StoreLetter.Series1.Length < 15 Then StoreLetter.Series1 = New String( "0", 0, _
CInt(15 - StoreLetter.Series1.Length)) & StoreLetter.Series1

The above line is where I get the Index out-of bounds. I know, long line wrapped LOL So, in the End, since my StoreLetter.Series1.Length=1, I need to tack 14 Zero's onto the beginning of it, then the value of StoreLetter.Series1 on the end to make a string with 15 Zero's in this case.

Thanks
Tibby

Nov 20 '05 #1
6 1405
Hi Tibby,

|| StoreLetter.Series1 = New String( "0", 0, _
|| CInt(15 - StoreLetter.Series1.Length)) & StoreLetter.Series1

This effectively comes down to
S = New String ("0", 0, 14)

Now the String constructor which takes three arguments is expecting an
array of characters for the first argument, and the second and third are the
starting position within that array and the number of characters therefrom.

In formal syntax, therefore, the code is
S = New String (New Char() {"0"}, 0, 14)

Now you can see where the array comes from. The second parameter says
start at the first char. The second says take 14 chars starting at that point.

But the array doesn't go that far - and <that> is an 'Index out-of bounds'
error! :-)

You have to remember that "ABCDE" is shorthand for New Char() {"A", "B",
"D", "E"}. [And glad it is too!].

I have to agree that the error message could be much more informative,
though. It could tell you what the array is, what value you've given and what
the array limits are, for example. It could perhaps show you the particular
definition of the constructor that you're using.

But, hey, compiler technology has only been developing for around half a
century. Give them time!! ;-)

Regards,
Fergus

ps. For my college project I investigated adding 'human' (ie. useful) error
messages to a Pascal compiler. Adding such intelligence to a compiler can
easily increase the complexity by a factor of ten.
Do you think it's worth it? So do I. :-)
Do 'they'? Not so far. :-(
Nov 20 '05 #2
To make sure I'm understanding you, I cannot use this as a replacement for
the old
String("0",14) command of VB6?
Basically, it would be S=New String(New Char() {"A","B","C"},1,2) would make
S =
"AB"???

Well that's no good, urgghhhhhh, I was hoping they wouldn't mess with that
nifty little feature. SO what, a for..next loop to add these 14 Zero's onto
the front?

Tibby
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:#E*************@TK2MSFTNGP12.phx.gbl...
Hi Tibby,

|| StoreLetter.Series1 = New String( "0", 0, _
|| CInt(15 - StoreLetter.Series1.Length)) & StoreLetter.Series1

This effectively comes down to
S = New String ("0", 0, 14)

Now the String constructor which takes three arguments is expecting an
array of characters for the first argument, and the second and third are the starting position within that array and the number of characters therefrom.
In formal syntax, therefore, the code is
S = New String (New Char() {"0"}, 0, 14)

Now you can see where the array comes from. The second parameter says
start at the first char. The second says take 14 chars starting at that point.
But the array doesn't go that far - and <that> is an 'Index out-of bounds' error! :-)

You have to remember that "ABCDE" is shorthand for New Char() {"A", "B", "D", "E"}. [And glad it is too!].

I have to agree that the error message could be much more informative,
though. It could tell you what the array is, what value you've given and what the array limits are, for example. It could perhaps show you the particular definition of the constructor that you're using.

But, hey, compiler technology has only been developing for around half a century. Give them time!! ;-)

Regards,
Fergus

ps. For my college project I investigated adding 'human' (ie. useful) error messages to a Pascal compiler. Adding such intelligence to a compiler can
easily increase the complexity by a factor of ten.
Do you think it's worth it? So do I. :-)
Do 'they'? Not so far. :-(

Nov 20 '05 #3
Sorry, this is the entire Error message:
Index was out of range. Must be non-negative and less than the size of the
collection.

Not that that helps much LMAO
Tibby
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:#E*************@TK2MSFTNGP12.phx.gbl...
Hi Tibby,

|| StoreLetter.Series1 = New String( "0", 0, _
|| CInt(15 - StoreLetter.Series1.Length)) & StoreLetter.Series1

This effectively comes down to
S = New String ("0", 0, 14)

Now the String constructor which takes three arguments is expecting an
array of characters for the first argument, and the second and third are the starting position within that array and the number of characters therefrom.
In formal syntax, therefore, the code is
S = New String (New Char() {"0"}, 0, 14)

Now you can see where the array comes from. The second parameter says
start at the first char. The second says take 14 chars starting at that point.
But the array doesn't go that far - and <that> is an 'Index out-of bounds' error! :-)

You have to remember that "ABCDE" is shorthand for New Char() {"A", "B", "D", "E"}. [And glad it is too!].

I have to agree that the error message could be much more informative,
though. It could tell you what the array is, what value you've given and what the array limits are, for example. It could perhaps show you the particular definition of the constructor that you're using.

But, hey, compiler technology has only been developing for around half a century. Give them time!! ;-)

Regards,
Fergus

ps. For my college project I investigated adding 'human' (ie. useful) error messages to a Pascal compiler. Adding such intelligence to a compiler can
easily increase the complexity by a factor of ten.
Do you think it's worth it? So do I. :-)
Do 'they'? Not so far. :-(

Nov 20 '05 #4
Cor
Fergus,
Very intresting, I never take that long thinking processes.
But I find it always nice to see that it is so deep been investigated
And your explanation was of course very clear.
:-)
Cor
Nov 20 '05 #5
Cor
Tibby,
Before you will think it , I was making and sending my message long before I
saw your answer.
Cor
Nov 20 '05 #6
Hi Tibby,

|| urgghhhhhh

Lol.

|| S=New String(New Char() {"A","B","C"},1,2) would make
|| S = "AB"???

Almost. Be warned - indexing in .NET starts at 0 so S = "BC". But just to
keep you on your toes, the old string functions (Mid, et al) are stll
available but index from 1.

|| the old String("0",14) command of VB6

... you will be relieved to know, is still with us - repeat <char> <n>
times. The String constructor that you used is simply an alternate constructor
(for other purposes).

I should point out that "X" will fail in New String() if you use Option
Strict On - the required syntax being "X"c or "X"C to indicate a character.

|| for..next loop to add these 14 Zero's onto the front?

Now you know, you don't have to use a loop.

But you might like this one:
StoreLetter.Series1 = StoreLetter.Series1.LeftPad ("0"c, 15)

This makes StoreLetter.Series1 15 characters long, if it was less, padding
on the left with "0" as required.

Have a look at the String Class - there are some nice methods in it.

All the best, ;-)
Fergus


Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Berislav Lopac | last post by:
Consider this code: <?php class TestClass { private function TestMethod() { echo 1; }
8
by: Scott David Daniels | last post by:
I have started doing the following to watch for exceptions in wxPython. I'd like any input about (A) the interface, and (B) the frame before I throw it in the recipes book. import wx, os, sys...
8
by: David Sachs | last post by:
The following program illustrates an interesting effect of the way C++ resolves function overloading. I have verified with a member of the C++ stardard committee that the output shown is...
6
by: DENG | last post by:
hi all, i use SGMLParser to process HTML files, in order to do some optimizations, something like this: <i><b>TEXT1</b></i><b><i><u>TEXT2</u></i></b> optimise to
6
by: Rennie deGraaf | last post by:
In the last few days, I have discovered two "interesting" behaviours of the C language, both of which are apparently correct. Could someone please explain the reasoning behind them? 1. The...
7
by: David Sworder | last post by:
Hi, I'm developing an application that will support several thousand simultaneous connections on the server-side. I'm trying to maximize throughput. The client (WinForms) and server communicate...
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
1
by: Rakesh Roberts | last post by:
I think I have a very interesting cookie problem. I use form authentications on my application. Through out my application I started using a toggle control that persists its value for the session...
2
by: Michael Sutherland | last post by:
Here's an interesting problem I've come across. I'm writing a program that essentially generates random strings (its a simulator of the game Boggle) and sends them to a function that does a...
3
by: AdamMorris | last post by:
I have a very interesting problem and can't seem to figure it out. Basically I'm trying to make a Training Assistant: a window that will guide the user through the setup process of an online app....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.