473,399 Members | 2,774 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,399 software developers and data experts.

Specified cast is not valid

I get an error with my code whenever i want to sort an array for unique values.
_readingLabelArrayList.sort

Private Sub TrmMux_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrmMux.Tick
Me.TrmMux.Enabled = False
gmux.GetBitCount()

CType(_readingLabelArrayList(intarrayindex), Label).Text = gmux.MuxAnalogValues(1)
Me.TrmMux.Enabled = True
End Sub


I need to sort the the _readingLabelArrayList to see if there are unique values in that array. How can i do this?
Sep 5 '07 #1
7 1123
Plater
7,872 Expert 4TB
Does it tell you what type it is and what type it's trying to cast to in the error message (it might be happening behind the scenes)

Is your arraylist actually full of Labels and not just their text?
Sep 5 '07 #2
nateraaaa
663 Expert 512MB
I get an error with my code whenever i want to sort an array for unique values.
_readingLabelArrayList.sort

Private Sub TrmMux_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrmMux.Tick
Me.TrmMux.Enabled = False
gmux.GetBitCount()

CType(_readingLabelArrayList(intarrayindex), Label).Text = gmux.MuxAnalogValues(1)
Me.TrmMux.Enabled = True
End Sub


I need to sort the the _readingLabelArrayList to see if there are unique values in that array. How can i do this?
The following Example has served me well many times when I need to sort or find duplicate values in an arraylist.

Nathan
Sep 5 '07 #3
Does it tell you what type it is and what type it's trying to cast to in the error message (it might be happening behind the scenes)

Is your arraylist actually full of Labels and not just their text?

Below is the code i use to create and add the arraylist
Private Sub CreateControls()
'controls to put on the screen
Dim lblCharacteristic As Label
Dim lblName As Label
Dim lblReading As Label

Dim intLoop As Integer
Dim intReadingSize As Integer
Try
_charLabelArrayList = New ArrayList
_readingLabelArrayList = New ArrayList
_ReadingArrayList3 = New ArrayList

For intLoop = 0 To _partfile.gageList.Count - 1
lblCharacteristic = New Label
lblName = New Label
lblReading = New Label

With lblReading
.Font = New System.Drawing.Font("Times New Roman", 8, FontStyle.Regular)
.BackColor = System.Drawing.Color.White
.ForeColor = System.Drawing.Color.Black
.AutoSize = True
.BorderStyle = BorderStyle.FixedSingle
.Text = "-00.00"
intReadingSize = .Width
.AutoSize = False
.Text = ""
.Width = intReadingSize
.TextAlign = HorizontalAlignment.Center
.TabIndex = intLoop
.BringToFront()
.CausesValidation = True
'AddHandler .Click, AddressOf ReadingLabel_Click
End With
_charLabelArrayList.Add(lblCharacteristic)
_readingLabelArrayList.Add(lblReading)
_ReadingArrayList3.Add(lblReading)

Next

Catch
MsgBox("Runtime CreateControls Error" & vbCrLf & vbCrLf & Err.Description, MsgBoxStyle.Critical, "CreateControls Error...")
End Try
End Sub
Sep 5 '07 #4
Plater
7,872 Expert 4TB
Hmm well what I would recomend trying is to do a .GetType().Name or a value from the arraylist and see what it *thinks* it is.
Sep 5 '07 #5
Hmm well what I would recomend trying is to do a .GetType().Name or a value from the arraylist and see what it *thinks* it is.

Plater would it even make sense, Im trying to populate an arraylist then i need to make sure that each location in the array list is unique if the location is not unique i would then run the program again and populate another arraylist, and then i would compare the arraylist2 to see if it has unique numbers...Would arraylist be the best way of going?


How would i implement the GetType in my arraylist?
Sep 5 '07 #6
Plater
7,872 Expert 4TB
Well I'm not sure why you have an arraylist of labels, who's text property should contain unique numbers?
Why not just make an arraylist of integers (or floats or whatever) and then once those are unique, create your labels from there?
Sep 5 '07 #7
[quote=Plater]Well I'm not sure why you have an arraylist of labels, who's text property should contain unique numbers?
Why not just make an arraylist of integers (or floats or whatever) and then once those are unique, create your labels from there?[/QUOTE

The only reason im converting these arraylist of lables to text properties is because i have linear stage that moves in increment. I populate my screen text box with the values of the linear stage that i return from the (gmux.MuxAnalogValues(1)). That type of arrangement works jsut fine, however now because we are being very critical about the data that is being returned i now have to make sure that my arraylist and every value in there is unique, therefore i must somehow compare the values in the arraylist.


Can you direct me in the best possibility?

I hope this is clear enough and i apprieciate all the help.
Sep 5 '07 #8

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

Similar topics

0
by: Tao | last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and tried to test it out. I created an ASP.NET project using the wizard and tried to run it by hitting "F5". I got an exception:...
2
by: Fabian | last post by:
Hi, I work with asp.net 2.0 and I have a intermittent error, only happens a few times a day. In the page I evaluate a Query String and then I get data form a database. The code snipped: ...
0
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
0
by: Alan Z. Scharf | last post by:
this question in datagrid group for several days with no repsonse. I'm hoping for an answer her because of greater activity in this group. No cross-posting intended. Thanks....
0
by: Tao | last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and tried to test it out. I created an ASP.NET project using the wizard and tried to run it by hitting "F5". I got an exception:...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
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,...
0
jinu1996
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...
0
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,...
0
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...

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.