Results 1 to 4 of 4

Thread: 1 more amazing question!!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99

    1 more amazing question!!!

    ok, to all the guys that read my last post on accessing a control out side of the form class, the solution is below, change it to what eva u want but the demo situation is as follows, 2 classes. one class is the form1 class the other class has one sub, the form also has a textbox, to get access to the textbox from the sub:

    +public sub form1
    +public class SMTP
    -public sub SMTP

    in the sub dim's just add this line(edit it first)

    dim anynamehere as formnamewithcontol

    now when you need it use the following, when you press the dot, u should have a fun menu appear, thenu can use .textbox1.text or what eva , hope this helps ppl

    anynamehere.


    LOL-==========================================
    i almost forgot that i have a question to ask, GOMEN....
    i have to save some settings but i dont think i want an ini file, i want an XML file like ppl have been talking about, i have seen then in some programs and they looks good and probibly easy to use, so how do i save stuf to an XML file and how do i get stuff back from aqn XML file tnx guys

    TrAcER

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Go to the www.vb-world.com site. Then in the interaction menu, there is a codeback item. Click it.
    Click on the C# section. I have submitted a way to save settings to the registry, and someone else has went behind me and modified my code to save settings to an xml file. If you can translate C# code to VB (shouldn't be that hard) then you will have it all.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    man, seems like im makeing a mountin out of a mole hill here, there must be an easyer way, im learning vb.net now and c# afterwards, so i dont think this is too good for me, anyone else have a tutorial or a code snipit already in vb Gomen.. but this seems like alot of work, i could take the easyway out and save to the registy but i dont wanna, thats not good practice

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can just load the xml file into a dataset and work with it and save it back to an xml file.

    VB Code:
    1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    2.         'read data from file
    3.         Dim ds As New DataSet()
    4.         'loda options xml file
    5.         ds.ReadXml(Application.StartupPath & "\test.xml")
    6.         Dim dr As DataRow
    7.         dr = ds.Tables("Options").Rows(0)
    8.         'put the options in local variables or whatever
    9.         'i just stacked them in a string since this is just a demo
    10.         'you could also just leave them in the dataset and use it as I have done here
    11.         Dim Opts As String
    12.         Opts = dr("Option1")
    13.         Opts &= ControlChars.NewLine & dr("Option2")
    14.         Opts &= ControlChars.NewLine & dr("Option3")
    15.  
    16.         'show the result
    17.         MsgBox(Opts)
    18.  
    19.         'write to file
    20.         dr("Option1") = "Item1"
    21.         dr("Option2") = True
    22.         dr("Option3") = 3.5
    23.         ds.WriteXml(Application.StartupPath & "\test.xml")
    24.  
    25.     End Sub

    And here is the xml file. Remember to put it in the bin folder or wherever the exe is.
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <Options>
    	<Option1>Option1</Option1>
    	<Option2>Another Option</Option2>
    	<Option3>5.555</Option3>
    </Options>
    You could have different rows be different users and stuff like that as well.

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