Results 1 to 5 of 5

Thread: Problems creating a tabbed network app

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    3

    Question Problems creating a tabbed network app

    Ok, I know I'm in WAY over my head here, but that's been the story of my life for 4 decades, so here goes:

    I'm trying to create a server/client app for playing RIFTS® across a network that consists of a simple(HAH!) client character sheet that logs into a server, allowing the GM (server app) to view/modify data. I don't have the winsock part started yet, so we won't worry about that yet (Thank God!). My problem is that I want to find a way to perform a "quick load" of the more than 100 textboxes on the server side sheet without having to create 3 lines of code for each one. I have the textbox names stored in an array, so I can (hopefully) use that to iterate through all the names in a loop, but have no idea how to implement the load statement using an array reference. An example of the code I'm using is below, and I can more fully explain the concept I have in mind, if needed.

    VB Code:
    1. Private Sub btnAddTab_Click()
    2.   ' Adds a new tab when a new client connects, adding new textboxes for
    3.   ' each alterable attribute
    4.   Dim i, c As Integer, temp As String
    5.  
    6.   TabStrip1.Tabs.Add
    7.   tCnt = TabStrip1.Tabs.Count
    8.   TabStrip1.Tabs(tCnt).Caption = "Tab #" & tCnt  ' Testing purposes only, for now
    9.   ' To be replaced by the Client's Character name at a later time
    10.   cnt = txtName.Count
    11.   TextBoxNameArray = Array("txtName", "txtAlign", "txtHP", "txtCHP", "txtSDC", "txtCSDC", _
    12.   "txtLvl", "txtEXP", "txtOCC", "txtIQ", "txtSkB", "txtME", "txtSVPI", "txtMA", _
    13.   "txtTrust", "txtPS", "txtDmgB", "txtPP", "txtStrPryDdg", "txtPE", "txtCmDthPs", _
    14.   "txtPB", "txtCharm", "txtSpd", "txtFPM", "txtPPE", "txtISP")
    15.   c = UBound(TextBoxNameArray)
    16.   For i = 0 To c
    17.     ' The block below is where I'm having trouble
    18.     '------------------------------------------
    19.     temp = TextBoxNameArray(i)
    20.     Load frmServer.Controls(temp)(cnt)
    21.     TextBoxNameArray(i)(cnt).ZOrder 0
    22.     '------------------------------------------
    23.   Next
    24.   'Load txtName(cnt)
    25.   'txtName(cnt).Text = TabStrip1.Tabs(tCnt).Caption
    26.   'txtName(cnt).ZOrder 0
    27. '  Stop
    28. End Sub

    Now, obviously, the code I have in there is not only non functional, it throws errors. This is also a greatly reduced version of the array, since there are 184 textboxes to be used (unless I find a better way to implement this). I'm not even certain if there's a way to load controls in the manner I want (Fumbling NOOB here), but I'm hoping, since it will reduce the code size tremendously.

    The commented out lines at the bottom of the example illustrate how each textbox is individually loaded, so you can see what I have to do, per textbox, to load each new tab with data. I'm sure there are better ways to do this, but I'm learning by trial and error here... Quite possible the WORST way to learn this...

    Ok, I've talked enough. Thanx for looking, and any suggestions are humbly and gratefully accepted.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Problems creating a tabbed network app

    Welcome to VBF!

    Not sure what that array is for ... however what you can do is create a control array (paste one textbox on the form in design and set its Index = 0) and at runtime simply create new instance as follows (you did attempted):
    VB Code:
    1. With frmServer
    2.     For i = 1 To intSomeUbound 'control array member with index 0 already exist
    3.         Load .Text1(i)
    4.         .Text1(i).Move iLeft, iTop 'determine correct position
    5.         'you may need to set text property here
    6.         'you may need to set TAG property here so you can determine later what is what
    7.         .Text1(i).Visible = True
    8.     Next
    9. End With
    NOTE: there is another technic exist (controls collection) but using control array might be much easier to handle:
    VB Code:
    1. Private Sub Text1_Change(Index As Integer)
    2.     Select Case Index 'or Text1(Index).Tag (or some other identifier)
    3.         Case 0
    4.             'do something
    5.     End Select
    6. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    3

    Re: Problems creating a tabbed network app

    Quote Originally Posted by RhinoBull
    Welcome to VBF!

    Not sure what that array is for ... however what you can do is create a control array (paste one textbox on the form in design and set its Index = 0) and at runtime simply create new instance as follows (you did attempted):
    Thanx for the warm welcome, Rhino.

    ...Which I have. The final lines within the sub show the methods I'm using to create a new instance in the control array. So far, so good. My problem lies in the nearly 200 different controls needed to be loaded on each tabbed page, each one needing 3 lines of code to load, fill with the proper text/caption and bring to the front. Fortunately, I found a way (cleverly using a 'depth ordering' trick I stumbled across) to make the same labels repeatable across each page for all the controls, reducing the coding (and the control count, which I know is near critical mass) a great deal.

    Quote Originally Posted by RhinoBull
    NOTE: there is another technique existing (controls collection) but using control array might be much easier to handle:
    This sounds like possibly a very worthwhile option to consider. I'll see what I can find on the subject. Any info on where best to look for material on this subject would be sheer happiness to me.

    [edit]
    BTW. The array is a list of all the textbox names for one section of the page. I'm hoping to iterate through that list within a loop to load the controls (in this example, textboxes) to drasticly reduce coding. This, in fact, is the entire crux of my problem. I can provide a link to the project so far, if you like, with all the source code in zip format, if needed.
    [/edit]
    Last edited by Dave_Morton; Mar 26th, 2005 at 01:51 AM.

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Problems creating a tabbed network app

    To "drasticly reduce coding" use CONTROL ARRAYS.
    In the sample I presented in my previous post I suggested that you might need to set TAG property for each new textbox created - after reading your reply I'd say that it might work for you the best. Tag would represent your textbox's "name", you may use that array to keep all "names" so when you need to load more textboxes you simply iterate through array and set Text1(i)>Tag = MyArrayOfNames(i).
    To identify any particular textbox from control array use the following sample:
    VB Code:
    1. Private Sub Text1_Click(Index As Integer)
    2.     Select Case Text1(Index).Tag
    3.         Case "txtName"
    4.             'do something
    5.         Case "txtAlign"
    6.             'do something
    7.         Case "txtHP"
    8.             'do something
    9.     End Select
    10. End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    3

    Re: Problems creating a tabbed network app

    Yup! I think that will take care of it nicely. Thanx for the tip, and I'll see about implementing that this evening. I'll let you know how it comes out.

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