Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 3,149
» Latest member: Hansonflielfife
» Forum threads: 857
» Forum posts: 3,646

Full Statistics

Online Users
There are currently 4 online users.
» 0 Member(s) | 1 Guest(s)
Bing, Google, Yandex

Latest Threads
Womans from your city - V...
Forum: Random Discussion
Last Post: iHOMEz
02-27-2025, 12:59 PM
» Replies: 1
» Views: 2,844
Looking for Adventure? Fi...
Forum: Random Discussion
Last Post: iHOMEz
01-08-2025, 11:00 PM
» Replies: 1
» Views: 1,872
Find Local Women Looking ...
Forum: Random Discussion
Last Post: iHOMEz
12-27-2024, 12:11 AM
» Replies: 0
» Views: 1,014
Prettys Womans in your to...
Forum: Random Discussion
Last Post: iHOMEz
10-30-2024, 07:45 AM
» Replies: 0
» Views: 1,849
Prettys Womans in your ci...
Forum: Random Discussion
Last Post: iHOMEz
10-26-2024, 10:50 AM
» Replies: 0
» Views: 1,788
Beautiful Womans from you...
Forum: Random Discussion
Last Post: iHOMEz
10-19-2024, 02:48 PM
» Replies: 0
» Views: 1,925
Prettys Womans in your ci...
Forum: Random Discussion
Last Post: iHOMEz
10-06-2024, 05:00 PM
» Replies: 0
» Views: 2,053
Supreme Сasual Dating - A...
Forum: Random Discussion
Last Post: iHOMEz
06-14-2024, 11:28 AM
» Replies: 0
» Views: 2,875
Beautiful Womans in your ...
Forum: VB.NET
Last Post: iHOMEz
06-09-2024, 09:23 PM
» Replies: 0
» Views: 3,063
Hangman in Rust
Forum: Other
Last Post: brandonio21
02-04-2018, 11:14 AM
» Replies: 2
» Views: 22,634

 
  Reading and Wrinting XML Files
Posted by: Snake_eyes - 11-17-2012, 06:35 AM - Forum: Code Snippets - Replies (1)

Here is the most simple way to read and write an xml file with attributes and values.

For the sake of this example let's say we have an application that on form load creates toolstrip butons that when cliked load a web page on a web browser

First of all let's see the format of the Xml file

Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<root>
   <ToolStipButtons>
      <item Name="btn1" url="www.google.com" btnName ="Google" />
      <item name="btn2" url="www.bing.com" btnText="Bing" />
      <item name="btn2" url="www.yahoo.com" btnText="Yahoo" />
   </ToolStripButtons>  
</root>

In order for the code to work we need to import System.Xml
[code2=vbnet]Imports System.Xml[/code2]

Reading the xml file

Now let's see about reading the values from the xml file and creating the buttons.
[code2=vbnet]Public Sub CreateButons()
Dim Xml_Doc As New XmlDocument
Xml_Doc.Load(Application.StartupPath & "/AppSettings.xml")
Dim xmlNode As XmlNode
For Each xmlNode In xmlDoc.SelectNodes("/root/ToolStripButtons/item")
Dim NewBtn As New ToolStripButton With {.Name = node.Attributes("name").Value.ToString, _
.Tag = node.Attributes("url").Value.ToString, _
.Text = node.Attributes("btnText").Value.ToString} }
AddHandler NewBtn.Click, AddressOf NewBtn_Click
ToolStrip1.Items.Add(NewBtn)
Next
End Sub[/code2]

After this just create a sub named "NewBtn_Click" to handle the click event of the individual buttons

Writing the xml file

If changes occured to the ToolStripButtons and we need to save the new values to the xml file then we will use the folowing code:

[code2=vbnet]Public Sub SaveValues()

Dim settings As New XmlWriterSettings
settings.Indent = True
settings.NewLineOnAttributes = False

Dim Xml_doc As New XmlDocument
Xml_doc.Load(Application.StartupPath & "\AppSettings.xml")
Xml_doc.RemoveAll()

Dim Writer As XmlWriter = XmlWriter.Create(Application.StartupPath & "\AppSettings.xml", settings)

With Writer
.WriteStartDocument(True)
.WriteStartElement("root")
.WriteStartElement("ToolStripButtons")

For Each Btn As ToolStripButton In ToolStrip1.Items
'//Writes the Item Element
.WriteStartElement("item")
'// Writes the "Name" atribute and it's value
.WriteStartAttribute("name")
.WriteValue(Btn.Name)
.WriteEndAttribute()
'// Writes the "url" atribute and it's value
.WriteStartAttribute("url")
.WriteValue(Btn.Tag)
.WriteEndAttribute()
'// Writes the "btnText" atribute and it's value
.WriteStartAttribute("btnText")
.WriteValue(Btn.Text)
.WriteEndAttribute()
'// Writes the end of the item element
.WriteEndElement()

Next
.WriteEndElement()
.WriteEndElement()
.WriteEndDocument()
.Flush()
.Close()
End With

End Sub[/code2]


Now just simply call the CreateButons() on the Form_Load event and the SaveValues() in the Form_Closing event(or any other sub for that mater, depending on your needs).

I also recommend using Try/Catch blocks in order to catch any unwanted errors that might occur

Print this item

  How do you programatically open a file in c# to append?
Posted by: complete - 11-17-2012, 03:03 AM - Forum: C#.NET (Visual C# 2010/2008) - Replies (1)

How do you programatically open a file in c# to append?

I tried searching online for an example and so far I have not found anything.

There is System.IO.StreamWriter and there is System.IO.StreamReader but there is no StreamAppend. Is there some way to use StreamWriter without overwritting the content of the existing file? Is there some way to use System.IO.Stream with some sort of appending criteria?

Print this item

  TwitterVB2
Posted by: Pete2709 - 11-08-2012, 03:17 AM - Forum: Programming Help - No Replies

Hi was wondering if you have any source code on displaying a users profile in the twittervb2 api followed your tut and have developed it.

Regards

Pete2709

Print this item

  How do I check if a user has a certain role in their profile
Posted by: kismetgerald - 11-07-2012, 08:27 PM - Forum: Programming Help - Replies (4)

Good evening all,

I need some help. I'm trying to query my MySQL database to see if the currently logged on user to my application has certain rights/role. If the queried value does exist, then I want to enable a certain menu item.

Your help would be greatly appreciated.

Here's my code - what am I not doing right?:

[code2=vbnet]Public Sub checkAccessLevel()
Dim dbConn As New MySqlConnection(String.Format("Server={0};Port={1};Uid={2};Password={3};Database=parts", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password))
Dim dbQuery As String = "SELECT Level = 'Admin' FROM users WHERE username = '" & FormLogin.TextBoxUsername.Text & "'"
Dim dbAdapter As New MySqlDataAdapter(dbQuery, dbConn)
Dim dbData As MySqlDataReader

Try
dbConn.Open()
dbData = dbAdapter.SelectCommand.ExecuteReader
If dbData.HasRows() = True Then
TSMenuItemOptions.Enabled = True
Me.Refresh()
Else
TSMenuItemOptions.Enabled = False
End If
dbData.Close()

Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
End Try
dbAdapter.Dispose()
dbConn.Close()
End Sub[/code2]

Print this item

  USB drive booting help?
Posted by: Derek275 - 11-06-2012, 01:49 PM - Forum: Computing - Replies (5)

I was wondering if anyone had any videos on how to change the settings on Windows 7 to boot from a USB drive and how to change It back to boot to my regular Windows 7 in case I decide I don't like Ubuntu? I'm fairly new to Linux so any other tutorials on it would be appreciated, too

Print this item

  Help with XML documents and loops?
Posted by: Derek275 - 11-06-2012, 05:11 AM - Forum: VB.NET (Visual Basic 2010/2008) - Replies (9)

I am not a master at the VB language. I am fairly new to actually trying to learn the language. I am writing a program, that requires that needs to do the following things:

* Read the XML document
* Create a ToolStripButton for each childnode in the XMLDocument with the text <name>
* Add handlers tI each button created that, when clicked, will navigate a web browser to the text in one of the other childnodes <URL>
* Change other properties according to diffrent buttons to diffrent child nodes.

I might have child nodes wrong, I'm not a master at XML documents.

But if you need to see the code I previously tried, I'll have to get on my computer when I get home.

I know how to do it in c#, but how would I do it in vb?

Print this item

  Help with Codeplex
Posted by: Derek275 - 10-29-2012, 04:13 AM - Forum: Share your programs! - Replies (1)

I might not have posted this in the right place...

But I have a program (I might share it later) and want to post it on Codeplex. I have a page for it, have my first release uploaded, everything BUT uploaded source code.

I'm not too thrilled to HAVE to do this, but when I go to, I can't find an upload source button

How do I do this or how do I get around uploading it period?

Print this item

  Script Help
Posted by: manishshrestha60 - 10-28-2012, 06:31 PM - Forum: HTML/CSS/PHP (Web Development) - Replies (2)

Can some one help me with the script like this. I want the script of referring and unlock the link and redirect to next page or something like that.
<!-- m --><a class="postlink" href="http://freeleaguecodes.com/ref/">http://freeleaguecodes.com/ref/</a><!-- m -->

Print this item

  Random Number Generator
Posted by: manishshrestha60 - 10-28-2012, 06:26 PM - Forum: Programming Help - Replies (4)

I need help with random number generator and the number has to about 15 digit for example like this 123456789012345. Any help will be appreciated

Print this item

  You can now mark posts as "solved"!
Posted by: brandonio21 - 10-27-2012, 11:44 AM - Forum: Computing - No Replies

Hey guys! After a little bit of tweaking, BP Forums now has the ability to mark posts as solved!! What does this mean? Well, everytime a correct answer is given, you can mark the answer as correct, and cool little check marks appear! This will help people find their answers quickly and make navigating the forums a little easier! I hope you guys enjoy this!

Print this item