Click to See Complete Forum and Search --> : Control Arrays
George1111
May 27th, 2009, 07:58 PM
As we know, with VB.Net I cant have a control array eg, Text1(1).text , Text1(2).text etc
This poses a slight problem to me when migrating my VB6 App as I use this feature considerably
I was wondering if the following was possible in VB.Net
1) Create a String Array
eg,
Dim ContArr(10) as String
2) Load the ContArr with NON INDEXED control Names
eg,
ContArr(1) = "Text1.text"
ContArr(2) = "Text2.text"
ContArr(3) = "Text3.text"
ContArr(4) = "Text4.text"
3) Use the ContArr to Point to the Control to be Used
THIS IS THE BIT I DONT UNDERSTAND HOW TO DO
Something like
"the control name held in ContArr(I)" = CustomerCode
Is this possible ?
dglienna
May 27th, 2009, 08:07 PM
Re-think that. What you need is a CLASS, maybe a field, or even a record.
You can easily create instances of a class, and keep your information there. Just use one set of textboxes, with meaningful names for the destination/output
George1111
May 27th, 2009, 09:12 PM
The bottom line is I am simply trying to duplicate Control Indexing, in the simplest manner possible
I suggested
"the control name held in ContArr(I)" = CustomerCode
Trying to Duplicate the VB6 possibility of
Text1(I) = CustomerCode
It may not be possible - if thats the case then I need to bite the bullet and change the way my programs work completely
HanneSThEGreaT
May 28th, 2009, 12:54 AM
Why not just use Control Collections ¿ :confused: :)
George1111
May 28th, 2009, 09:30 AM
Control Collections - Gee that sounds so simple - is that a One Liner like my example or is it a War and Peace effort ? (I'm new to VB.Net so I don't have a clue what you mean)
Are you able to show an example please using my example of trying to duplicate Text1(1), Text1(2) etc
Thanks
HanneSThEGreaT
May 29th, 2009, 12:50 AM
Control Collections - Gee that sounds so simple - is that a One Liner like my example or is it a War and Peace effort ? (I'm new to VB.Net so I don't have a clue what you mean)
Shoot me for trying to help George... So, sorry. :confused:
OK, back to the question at hand. George, some time ago, you asked the exact same question, and you basically got the exact same answers / some small variations on these answers ( Collections ) as well. Have a look at these threads :
http://www.codeguru.com/forum/showthread.php?t=396462&highlight=control+array+george
http://www.codeguru.com/forum/showthread.php?t=396882&highlight=control+array+george
http://www.codeguru.com/forum/showthread.php?t=410449&highlight=control+array+george
Once again, I apologise for trying to help. I always thought that that, is what CG is all about... :eek:
George1111
May 30th, 2009, 09:53 AM
Hi Hannes
Firstly, Sincere apologies for pushing the wrong buttons .. you really are a patient and helpful friend who deserves better than my frustrations:o
You are right - I did ask the same question before - I was hoping to get a different answer - I was hoping it was possible in VB.Net to "Write out a VB Instruction, then cause it to be executed"
Something like writing out a script file in VB6 then executing it, I believe
The script files (from memory) can even be keyed into a text box then executed from the string produced
Hopefully this could also be done in VB.Net (process a script file)
Is this possible ?
dglienna
May 30th, 2009, 11:40 AM
You mean you want to let a user type FORMAT C: and see what happens?
If you want, you can create a batch file, and execute it in a separate thread, but that could have bad results...
George1111
May 31st, 2009, 05:10 AM
I was hoping you could key into a textbox, an instruction like
TextBoxABC.Text = "AAAAAAAAAAA"
And by sending that text to a script processor, it would put the value into the textbox. I was hoping this could be executed from within the actual program, rather than launching a batch file.
I have a vague memory you can do this in VB6 (even though I've never done it myself)
George1111
May 31st, 2009, 09:46 AM
I think I've found the VB6 routine for what I am trying to do in VB.Net
THe references are in the vB6 Application are:
Microsoft Script Control 1.0
Microsoft Scripting Runtime
Attached is a VB6 Example of how Scripting works
My question is
Can this be done with VB.Net ?
It is called ........ ? (Same as VB6 ?)
Thanks
dglienna
May 31st, 2009, 12:53 PM
Did you read my post about the problems with scripting that users can access, but you can use jScript or regular Scripting
Converted:
Option Strict Off
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
' Add a reference to Microsoft Script Control 1.0
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim dbl1 As Double
Dim x As New MSScriptControl.ScriptControl
Dim z As Short, a As Short
Dim q As String
z = 55
a = 24
q = "*"
x.Language = "vbScript"
MsgBox(VB6.Format(x.Eval(z & q & a), "standard"))
' ===============================================
Dim str1 As String = "(5+50)*2/3"
dbl1 = (x.Eval(str1))
MsgBox(dbl1)
End Sub
End Class
This could be entered into a textbox:
str1 = "Format C:\"
dbl1 = (x.Eval(str1))
George1111
May 31st, 2009, 01:41 PM
I see your point about the danger - I guess you'd have to check what is being keyed looking for dangerous commands, before executing them
I was looking more to build commands and instructions internally and then execute them internally
eg, If I can script
"Text1.Text = 'AAAAAAAAAAAAAAA'"
Then I have finally achieved the ability to then also script
"Text2.Text = 'BBBBBBBBBBBBBB"
Which therefore means I can reiterate through a scripted loop and effectively achieve the same as I would in VB6 indexed text boxes
Text1(1) = "AAAAAAAAAAAAAAAA"
Text1(2) = "BBBBBBBBBBBBBBBB"
dglienna
May 31st, 2009, 02:24 PM
Use a CLASS that contains Control, and String values, and then create instances of each class.
Public Class cntlClass
Private cntl As Control ' Textbox1
Private myval As String ' "AAAAAAAAA"
End Class
Then, you could use this:
dim cx as list(of cntlClass)
George1111
June 1st, 2009, 01:23 PM
This sound like it is getting close to the mark. and more importantly, looks simple enough for a concrete head like me to understand.
Thanks - I'll see how I can use this in my new journey with VB.Net
HanneSThEGreaT
June 2nd, 2009, 09:41 AM
The "logic" by David ( in Post # 13 ), George, is called Generics. A very very powerful technology present with .NET, which can be so easily implemented. Yes, at first when you delve into Generics etc. it may seem a bit odd, or tough, but, once you get the hang of it, you will struggle to find places where not to use it :)
When you have time, you could look at these :
http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c11887
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
BTW, I also had a tough day ( I hate being sick ), so it's me that should apologise for my previous ( childish ) post, George! :D
George1111
June 3rd, 2009, 06:51 AM
Hannes - I regard you as a true friend who has personally helped me out of so much strife of the years and value your friendship dearly.
For this I will always be grateful, and its the wonderful people of Code Guru who give .. give .. and give some more which makes Code Guru such wonderful place.
My earliest experiences with code guru were to watch the "Grand master" Cimperelli, who nutured so many of us early learners, in a most gracious manner - if I can ever deal with problems even half as well as he taught us, I will be a contented man.
And the tenaciousness, and humour of WOF and JonnyPoet is a joy to behold.
Your nurturing Hannes has helped so many of us in a gentle way.
And how would Code Guru be without the enormous depth of experience and teaching brought to us by David.
There are so many more I love to help and be helped by - each one contributing a piece of the solving of so many puzzles
I just want to say THANK YOU to each and every one of you and am proud to be associated with such a fine bunch of energetic, unselfish, and professional people
CHEERS to you ALL !!! YOU ARE JUST THE BEST TEAM TO WORK WITH !!!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.