CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Control Arrays

  1. #1
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,901

    Control Arrays

    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,
    Code:
     Dim ContArr(10) as String
    2) Load the ContArr with NON INDEXED control Names

    eg,

    Code:
    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

    Code:
    "the control name held in ContArr(I)" = CustomerCode

    Is this possible ?

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Control Arrays

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,901

    Re: Control Arrays

    The bottom line is I am simply trying to duplicate Control Indexing, in the simplest manner possible

    I suggested

    Code:
    "the control name held in ContArr(I)" = CustomerCode
    Trying to Duplicate the VB6 possibility of

    Code:
    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

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Control Arrays

    Why not just use Control Collections ¿

  5. #5
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,901

    Re: Control Arrays

    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

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Control Arrays

    Quote Originally Posted by George1111 View Post
    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.

    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/showth...l+array+george

    http://www.codeguru.com/forum/showth...l+array+george

    http://www.codeguru.com/forum/showth...l+array+george

    Once again, I apologise for trying to help. I always thought that that, is what CG is all about...

  7. #7
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,901

    Re: Control Arrays

    Hi Hannes

    Firstly, Sincere apologies for pushing the wrong buttons .. you really are a patient and helpful friend who deserves better than my frustrations

    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 ?

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Control Arrays

    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...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,901

    Re: Control Arrays

    I was hoping you could key into a textbox, an instruction like

    Code:
    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)

  10. #10
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,901

    Re: Control Arrays

    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
    Attached Files Attached Files

  11. #11
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Control Arrays

    Did you read my post about the problems with scripting that users can access, but you can use jScript or regular Scripting
    Converted:
    Code:
    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:
    Code:
     str1 = "Format C:\"
     dbl1 = (x.Eval(str1))
    Last edited by dglienna; May 31st, 2009 at 01:35 PM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  12. #12
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,901

    Re: Control Arrays

    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

    Code:
    "Text1.Text = 'AAAAAAAAAAAAAAA'"
    Then I have finally achieved the ability to then also script

    Code:
    "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

    Code:
    Text1(1) = "AAAAAAAAAAAAAAAA"
    Text1(2) = "BBBBBBBBBBBBBBBB"

  13. #13
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Control Arrays

    Use a CLASS that contains Control, and String values, and then create instances of each class.

    Code:
    Public Class cntlClass
        Private cntl As Control ' Textbox1
        Private myval As String ' "AAAAAAAAA"
    End Class
    Then, you could use this:

    Code:
    dim cx as list(of cntlClass)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  14. #14
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,901

    Re: Control Arrays

    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

  15. #15
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Control Arrays

    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/...cle.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!
    Last edited by HanneSThEGreaT; June 2nd, 2009 at 09:45 AM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured