|
i am making a function that validate control using for each controlname in me.control...next
where "me" is the name of the actual form using this i can validate my controls but not with the order tab that the controls have it, the control collection is taking the last control for biginin to validate.
And the other problen is that i have a control different of controlname used in de for statement for example a command button, it give me a error becose is validating it...
i need some help please!!!
Gbyte
|
|
|
|
|
I have the same problem.
My form has over 100 controls.
I would like to loop throught the controls in a particular order. Is this possible?
I can loop through the controls using [ me.Controls(i) ] but the default collection does not contain the controls in the order I require. This was easy using the index property in previous versions.
eg Loop through Label_01 to Label_23 then Label_45 to label_62. I could do this using a Case statement but think that this is not good style and may slow the application.
If you can help I would be thankful.
Hollywood_t
|
|
|
|
|
' Run once after the form is loaded and conrtols are created
Dim slControls as SortedList
Dim i as Integer
for i - 0 to me.controls.count - 1
'You may include a CASE or IF statement if you want to selectively add
slControls.add(me.controls(i).name, i)
next
'In your event handler for each control that changes
'that is of interest to you write sub routines for adding, removing
'sorting, etc.....
'*include appropriate code to filter those controls you need
'slControls.Remove(me.controls(i).name)
'slControls.Add(me.controls(i).name, Index)
'To retrieve a control's info simply loop through the array
for i = 0 to slControls.count - 1
slControls.GetKey(i) ' Returns the key - in this example's case - the NAME
slControls.GetbyIndex(i) ' Returns the value - in this example's case - the Order in the Collection
' Do your validation here using the values returned from the array slControls
next
'*** NB - code has been typed - please check for errors ***
Hollywood_t
|
|
|
|
|
I have problem with accessing arrays of strings.
Below is a VB.NET code of function StructToByteArray, which is modified version of http://www.codeproject.com/useritems/readwritestructstobinfile.asp
'This function copys the structure data into a byte()
Private Function StructToByteArray(ByVal strukt As Object) As Byte()
Try
Dim buffer(Marshal.SizeOf(strukt)) As Byte
'Allocate the buffer to memory and pin it so that GC cannot use the space (Disable GC)
Dim h As GCHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned)
'copy the struct into int byte() mem alloc
Marshal.StructureToPtr(strukt, h.AddrOfPinnedObject(), False)
h.Free() 'Allow GC to do its job
Return buffer ' return the byte(). After all thats why we are here right.
Catch ex As Exception
BladPokaz(ex)
Return Nothing
End Try
End Function
And here are the sample structure:
<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Private Structure Str1
Friend dintVal As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=10)> _
Friend dintArr() As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=6)> _
Friend stringVal As String
End Structure
What we've got here is Integer value, array of Integer values and a String value.
The problem is how to define an array of Strings. The size of array
and size of String could be fixed.
I've tried other array types (SafeArray, ByValTStr, etc.) and define ArraySubType.
None of this worked for me.
Thanks in advance for your help.
Marc
|
|
|
|
|
Hi Marc,
If I understand the question correctly, the answer is simple:
<br />
Dim NumberOfElements as Integer<br />
NumberOfElements = 4 'for example<br />
Dim MyStringArray(NumberOfElements) as string 'Gives you an array, with 5 empty elements<br />
MyStringArray.SetValue("Hello", 0)<br />
MyStringArray.SetValue(" ", 1)<br />
MyStringArray.SetValue("World", 2)<br />
MyStringArray.SetValue("!", 3)<br />
'etc<br />
In other words, determine how many elements will be in your array, and then fill them up any which way you like.
Hope this helps you,
Johan
|
|
|
|
|
I want to have a structure like this:
<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Private Structure Str1
Friend dintVal As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=10)> _
Friend dintArr() As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=6)> _
Friend stringVal As String
<MarshalAs(UnmanagedType.ByValArray)> _
Friend stringArr as String()
End Structure
I don't know how to properly declare array of Strings, and its size,
inside above structure.
Now, look at the StructToByteArray function from my previous post.
When I had debugged its code I've noticed, that size of buffer
isn't calculating corectly.
Here is example of how I fill an instance of my structure (but it's typical):
Private struk1 As Str1
struk1.intVal = 25
struk1.bVal = True
ReDim struk1.stringArr(1)
struk1.stringArr.SetValue("here is text1", 0)
struk1.stringArr.SetValue("and here is text2", 1)
Marc
|
|
|
|
|
Hi Marc,
Just off the top of my head, I would say that you first need to change Friend stringArr as String() to Friend stringArr() as String . And then
<MarshalAs(UnmanagedType.ByValArray)> _<br />
Friend stringArr as String()
to
<MarshalAs(UnmanagedType.ByValArray)> _<br />
Friend stringArr() as String
Possibly you could try to determine the number of elements already in the MarshalAs bit:
<MarshalAs(UnmanagedType.ByValArray)> _<br />
Friend stringArr(DetermineNumberOfElementsHere) as String
Otherwise do I understand correctly that you did manage to do it with the integer array? If so, the only other suggestion I can come up with is to copy that same code and just change the type to string. I am sorry to say that this marshalling and structure business is a bit over my head.
Good luck,
Johan
|
|
|
|
|
>I would say that you first need to change Friend stringArr as String() to Friend stringArr() as String.
You are right. I had try it prevoiously and have forget to change it back.
>Possibly you could try to determine the number of elements already in the MarshalAs bit:
>Friend stringArr(DetermineNumberOfElementsHere) as String
That's not possible, because "Arrays declared as structure members cannot be declared with an initial size."
>Otherwise do I understand correctly that you did manage to do it with the integer array? If so, >the only other suggestion I can come up with is to copy that same code and just change the type to >string. I am sorry to say that this marshalling and structure business is a bit over my head.
That's the whole thing, it can't be done so easy. Because arrays and strings don't have a fixed length in .NET.
Thanks for your interest anyway.
Marc
|
|
|
|
|
marccp wrote: >Possibly you could try to determine the number of elements already in the MarshalAs bit:
>Friend stringArr(DetermineNumberOfElementsHere) as String
That's not possible, because "Arrays declared as structure members cannot be declared with an initial size."
OK, I've changed structure to class, so now I can define size:
<MarshalAs(UnmanagedType.ByValArray)> _
Friend stringArr(6) As String
But it hasn't changed anything.
My array of Strings is not properly copying into ByteArray
by the StructToByteArray function.
Instead of it there are random bytes in the buffer.
Anyone can help?
|
|
|
|
|
Friend Class frmMain
Does it mean that we can access the private,public and protected members of Class frmMain from another form say for eg: frmMain1.
|
|
|
|
|
|
If VB.NET has friend classes and C# doesn't, then I need to kill someone.
Christian Graus - C++ MVP
|
|
|
|
|
|
Could someone please help me with what must be simple issues:
1. How do I disallow null values in a datatable (change them automatically to "" for instance). Do I have to write my own routine to loop through the table and check when it is updated?
2. How do I get rid of a deleted row in a datatable? (The row seems to stay in the table even though its status becomes "deleted") Do I need to write my own routine to copy the data to a temporary table and then back into the working table?
3. How do I NOT display a given row in a datagrid (even though the row is still in the datatable). Again, do I have to write my own copy routine?
tia! and happy thanksgiving to all.
|
|
|
|
|
Hi,
1. (assuming that you fill your datatable from an sql query) Adapt the SELECT clause in your query like so: SELECT ISNULL(MyTable.MyField1, ""), ISNULL(MyTable.MyField2, ""), etc . This will return "" instead of NULL. Instead of "" you can use pretty much any string or number.
2. At the point in your code where the datatable has been edited (rows deleted, field values changes, etc), but before you do anything else with the dataset, you have to tell the dataset to accept changes made, like so: YourDataSet.AcceptChanges()
3. I don't think there is any ready property to do this (but I am far from expert). I have solved a similar problem, where I needed for the user to be able to "filter" out rows with 0 values in a certain column, without actually deleting them, like so:
<br />
Dim TempDataSet as New DataSet<br />
Private Sub CmdFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdFilter.Click<br />
TempDataSet.Clear()<br />
TempDataSet = MyMainDataSet.Copy 'Copy your original dataest into a temporary one<br />
'Do whatever you must here<br />
MyMainDataSet = TempDataSet.Copy 'and when you are done, copy it back<br />
MyDataGrid.DataSource = MyMainDataSet<br />
MyDataGrid.DataMember = "TableName"<br />
End Sub<br />
Otherwise, you will have to come up with your own code, yes.
Hope this helps you,
Johan
|
|
|
|
|
Dear All,
Is it able to rotate the string in a text box as a mirror .How can I?
|
|
|
|
|
use the StrReverse function of vb.net
example :
Dim lbl As String = "asp_net"
Label1.Text = StrReverse(lbl)
asp_net will be shown as ten_psa in Label1
i hope this is what you are looking for.
Take care
|
|
|
|
|
Not as a mirror, no. You'd need to create your own control for that.
Christian Graus - C++ MVP
|
|
|
|
|
Hi everybody,
My question could seem to be easy, but I'm a newbie in VB.NET development.
Is it possible to declare a multi-dimensionnal array, but containing different data-type. I mean :
I've got a array containing my own data (actually, it contains objects of type FrameInterpretor which contains some bytes arrays), and I would like to associate to this data an integer.
Thanks a lot for your replies,
Regards,
Ch'Portos.
Yop Yop !!
|
|
|
|
|
Seems like you need to use a Hashtable or Dictionary in which the key is your integer and the value is your FrameInterpreter. If you're using .NET 2 then Dictionary is the one to use. You should find examples in the MSDN documentation.
Kevin
|
|
|
|
|
Hi,
Thanks for your help, but I found another way to do what I want.
I simply created a private class in which I have 2 attributes, one of the FrameInterpreter type, one of Integer type.
After I use an array of objects of this new class
Ch'Portos.
Yop Yop !!
|
|
|
|
|
if i use this line -> myRestrictItems.Item(i).ReceivedTime
in the method i'm getting MissingMethodException ! i just cant understand why it is so?
this page shows that its a bug or something http://support.microsoft.com/kb/834063 but still i'm not able to get away with it !!
|
|
|
|
|
I think I had something similar to this a few weeks ago when using Analysis Services. The fix was to apply the latest Analysis Services service pack.
Kevin
|
|
|
|
|
hiho,
I've got 3rd parity dll and want to bind them in my code with "CreateObject". with "dim t as new dll.klasse" it runs but not with "CreateObject". The Code of the dll is not managed c++ code and i don't have the source code
|
|
|
|
|
CreateObject will NOT let you do something like Dim t As New MyClass . CreateObject is used for late-bound creation of objects.
In order to create objects using Dim , you have to add a reference to the .DLL and this will only work if the .DLL is COM-based.
So, how you can use this .DLL depends entirely on the .DLL and the version of VB you're using. You can't just use it "the way you want to".
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|