# .NET Thread



## Cromewell

Please post any questions relating to .NET here. Please indicate which language you are using and also specify which external libraries, if any, you are using.

You can also use this thread to post code you wish to share.


----------



## Aastii

Little bit of background - doing a program for my computing A-level and I need a log in system for part of it.. It only needs to be there and I get a crap ton of marks (it links in with other stuff, hence the alot of marks for a simple algorithm. The algorithm/code part is only worth maybe 1 mark, but what it ties in with gets a lot extra). However, the program I am making will, once I've made it into a program rather than just part of my qualifications course, actually be used, so of course I need more security than just log in and make an account, because it is easy to just go to the usernames file. This is extra outside of the course basically.

It doesn't need to be super secure, the people using it won't be very computer literate at all, and there isn't any sensitive information held directly other than NHS numbers (the number used to identify you in the NHS here in Britain), but you can't actually do anything with someone's NHS number unless you can go to the huge database of all of them.

I'm running it in VB.net 2010, and up to now have already make the bones of the program, and enough to get me most all of the marks in it. What I have currently done for the log in system:



		Code:
	

        uname = txtUser.Text
        pword = txtPass.Text
        counter = 0
        flag = 0

        'Open file for reading into Current array, then close the file once all files are in the array
        'Counter to track how many entries are in the file

        FileOpen(1, CurDir() & "\Users.txt", OpenMode.Input)

        While Not EOF(1)
            Input(1, Current(counter).username)
            Input(1, Current(counter).password)
            counter = counter + 1
        End While

        FileClose(1)

        'Compare the username and password input to the usernames and passwords in the users file
        'And change a flag accordingly to true if there is a match, else false if there is not

        For index = 0 To counter - 1
            If flag = False Then
                If Current(index).username = uname Then
                    If Current(index).password = pword Then
                        flag = 1
                    Else : flag = 0

                    End If
                Else : flag = 0

                End If

            End If
        Next

        'If the flag is true, close the form and load the main program, otherwise display a message that
        'the user name and/or password are incorrect

        If flag = True Then
            Me.Hide()
            frmHome.Show()
        Else
            MsgBox("Invalid Username or Password")
        End If



    End Sub


Which works, but as I say, isn't secure, and how to go about encrypting the username + password, I'm not sure


----------



## Cromewell

Do you necessarily need the user name enrypted?

Have a look at System.Security.Cryptography (http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx)


----------



## Aastii

Cromewell said:


> Do you necessarily need the user name enrypted?
> 
> Have a look at System.Security.Cryptography (http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx)



The username I suppose not.

Thanks for the link, will look ore into it and work out how to implement it into my program


----------



## Cromewell

I find it's hard to get good tutorials online for using .NET stuff. I've found this article though, hopefully it helps http://www.devarticles.com/c/a/VB.Net/String-Encryption-With-Visual-Basic-.NET/


----------



## tlarkin

I don't know .NET really, but why not prompt for the user name and password?   I am sure there is a way to get user interaction in .NET.   Otherwise, putting usernames/passwords in apps/scripts is never a good idea.   Even if you obfuscate it, not a good idea.


----------



## Cromewell

It looks to me that he is prompting for it, via a textbox. The encryption is for storing them in a database (or flat file as the case appears to be right now).


----------



## WeatherMan

This is a bit of an off topic question, but I am doing Visual Basic for my Software Development Unit.

What's the difference between between Visual Basic & VB.net? 

No this isn't coursework  I am just curious.


----------



## Aastii

Cromewell said:


> It looks to me that he is prompting for it, via a textbox. The encryption is for storing them in a database (or flat file as the case appears to be right now).



Close, it is actually 2 text boxes for input on a form that appears as the home for the program. You must log in before you are able to access anything, be it add data, edit or query the data.

And the data is indeed for storage. It will be stored encrypted, and when you put in the username and password it would be decrypted, checked against what has been typed in



Bootup05 said:


> This is a bit of an off topic question, but I am doing Visual Basic for my Software Development Unit.
> 
> What's the difference between between Visual Basic & VB.net?
> 
> No this isn't coursework  I am just curious.



VB.NET is part of the .NET framework from Microsoft (C.NET, C#.NET, C+.NET etc). It has certain pieces of code and ways to manipulate data that are different to VB6, but they are essentially the same thing. Microsoft just changed some stuff, and grouped all of the languages together into a single package - Microsoft Visual Studio


----------



## Aastii

Alright, I've hit another wall

Trying to write to my file, I've used a single object to test if it will go in before I go putting 40+ pieces of data in, or rather the code for it, just to find I did it wrong and wasted my time 

I've got a combo box with options for hospital's a patient is at to collect the data.

That is then read into a public array called template, which is of a structure called Patrec, which has a location for every different piece of data, so everything read into the array, then bulk written to the text file.

To write the hospital to the array:





		Code:
	

    Private Sub cmbHosp_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbHosp.SelectedIndexChanged
        template.hospital = cmbHosp.SelectedIndex
    End Sub


And then, at the end of putting the data in (spread over 3 forms for clarity):



		Code:
	

 FileOpen(1, CurDir() & "\Hospital.txt", OpenMode.Append)

        Write(1, template.hospital)

        FileClose(1)


----------



## Aastii

Doesn't matter, I sorted it. The problem was using Input rather than WriteLine, and looking in the wrong directory


----------



## kobaj

C# question (not pertaining to .net in any way really, but C# uses the .net framework and I didn't feel like making a new thread...)

I'm toying around with C# generics <T>, and inheritance, and basically wondered if the following was a bad way of doing things,



		Code:
	

namespace K_OS_SlimDX
{
    public class CustomVertex
    {
        public class TransformedColored : CustomVertex
        {
        }
    }
}


You'll note that TransformedColored inherits from CustomVertex...which has a TransformedColored that inherits from CustomVertex...which (and its recursive all the way down). 

But it compiles, without a hitch. So I take it my code is ok?

For the record, I know the correct way is like below. But I really just want to know why the above works?



		Code:
	

namespace K_OS_SlimDX
{
    abstract class CustomVertex
    {
    }
        public class TransformedColored : CustomVertex
        {
        }
}


----------



## Cromewell

the thing with creating the class as you did in #1 is that it only exists inside the scope of CustomVertex. I don't know how that inheritance will work though.


----------



## S.T.A.R.S.

The "abstract" modifier is used in classes,methods and properties.Abstract modifier is used when you want the class to be a base class for other classes.
The modifiers which are not allowed in an "abstract" method declaration are: "static","virtual" and "override".
An "abstract" class has to provide implementations for all of its interface members and CANNOT be a static logically since you cannot even use the "static" keywords to create the static methods.
For example:

abstract class ComputerForum
{
    public abstract void LifeSucks(); //This is a method...
}
class ThisForumRules:ComputerForum
{
   public override void LifeSucks()
   {
       MessageBox.Show("It sure does ");
   }
}

And then somewhere such as in the simple button CLICK event you can execute the method by creating the new instance of the class called "ThisForumRules" by doing it this way:

ThisForumRules omgReally=new ThisForumRules();
omgReally.LifeSucks();


So in this example the ABSTRACT class called "ComputerForum" contains the public abstract void method called "LifeSucks" which we then used in the class called "ThisForumRules" which took it's basis from "ComputerForum" abstract class.And then in the class called "ThisForumRules" we simply wrote a simple code which will be executed each time the "LikeSucks" method is called.In this case it is a simple message box.

So in your case if you want to have class and then the class INSIDE that class,you should more use ABSTRACT class to store methods which later you can use in ANY classes and initiate them from any events by creating the new instances of those classes.




Cheers!


----------



## M1kkelZR

i have a question about C#.

so we have to use 3 checkboxes and all of the check boxes has its own numerical value.

heres an example for what i have.



		Code:
	

i private void btnBereken_Click(object sender, EventArgs e)
        {
            int beurs = Convert.ToInt32(chkBeurs.Checked);
            int kamers = Convert.ToInt32(chkKamers.Checked);
            int actief = Convert.ToInt32(chkActief.Checked);
            int som;
            if (chkBeurs.Checked)
            {
                beurs = 5;
            }
            else if (chkKamers.Checked)
            {
                kamers = 5;
            }
            else if (chkActief.Checked)
            {
                actief = 10;
            }
            som = 30 - beurs - kamers - actief;
            txtTotaal.Text = Convert.ToString(som);
        }


Problem is it wont calculate everything right.

it will calcualte it if i only check 1. but if i have more than 1 checked it will somehow think it has to make all of them (5,5 and 10) and make it 6. so it will be 30-6

help please?


----------



## Cromewell

The problem is your code can only hit one of the branches. Fortunately, it is an easy fix:


		Code:
	

i private void btnBereken_Click(object sender, EventArgs e)
        {
            int beurs = Convert.ToInt32(chkBeurs.Checked);
            int kamers = Convert.ToInt32(chkKamers.Checked);
            int actief = Convert.ToInt32(chkActief.Checked);
            int som;
            if (chkBeurs.Checked)
            {
                beurs = 5;
            }
            if (chkKamers.Checked)
            {
                kamers = 5;
            }
            if (chkActief.Checked)
            {
                actief = 10;
            }
            som = 30 - beurs - kamers - actief;
            txtTotaal.Text = Convert.ToString(som);
        }

That said, the behaviour looks weird. You seem to be setting each variable to 1 or 0 depending on if it is checked then checking if it's checked and setting it to a new value.


----------



## M1kkelZR

Cromewell said:


> The problem is your code can only hit one of the branches. Fortunately, it is an easy fix:
> 
> 
> Code:
> 
> 
> i private void btnBereken_Click(object sender, EventArgs e)
> {
> int beurs = Convert.ToInt32(chkBeurs.Checked);
> int kamers = Convert.ToInt32(chkKamers.Checked);
> int actief = Convert.ToInt32(chkActief.Checked);
> int som;
> if (chkBeurs.Checked)
> {
> beurs = 5;
> }
> if (chkKamers.Checked)
> {
> kamers = 5;
> }
> if (chkActief.Checked)
> {
> actief = 10;
> }
> som = 30 - beurs - kamers - actief;
> txtTotaal.Text = Convert.ToString(som);
> }
> 
> That said, the behaviour looks weird. You seem to be setting each variable to 1 or 0 depending on if it is checked then checking if it's checked and setting it to a new value.



well the thing it was supposed to be is if you check the first one, the total which is 30 has to have 5 taken off,  and same with the second and third but the third takes 10 off.

then i needed to make it read multiple checks but for some reason it will only do this 30 - 5 then it will se the other 2 checks as 1 instead of 10 or 5. my teacher explained it and i was like yeah right... im a game and server programmer not a simple calculation programmer lol

but atleast i now know what i did wrong. instead of if-if-if i did if-if else-if else. which means it will look for alternatives and change the values of the other checks as it cant figure it out.

thanks. i think you'll see alot of simple stuff that ill post here, just because i overthink everything. if the forum had a thanks or rep button youd get one straight away haha! so thanks man i appreciate the help


----------



## S.T.A.R.S.

Keywords IF,ELSE IF and ELSE cannot be used all at the same time.
IF executes statements if it matches whatever you want to match.If not then it automatically goes to ELSE IF to see if it matches whatever you want to match.If not then it automatically goes to ELSE which always executes if NONE of your checks (IF or ELSE IF) match anything you want to match.For example:

if(textBox1.Text=="One")
{
//Execute the code if it matches 1 and skip the rest...
}
else if(textBox2.Text=="Two")
{
//Execute the code if it matches 2 and skip the rest...
}
else if(textBox3.Text=="Three")
{
//Execute the code if it matches 3 and skip the rest...
}
else
{
//Execute the code if first 3 things do not match whatever is that you want to match...
}



You can put ELSE IF posibilities as much as you want.
You can also use SWITCH keyword for the same purposes,but I rather use IF.



Cheers!


----------



## Cromewell

Raz3rD said:


> well the thing it was supposed to be is if you check the first one, the total which is 30 has to have 5 taken off,  and same with the second and third but the third takes 10 off.
> 
> then i needed to make it read multiple checks but for some reason it will only do this 30 - 5 then it will se the other 2 checks as 1 instead of 10 or 5. my teacher explained it and i was like yeah right... im a game and server programmer not a simple calculation programmer lol
> 
> but atleast i now know what i did wrong. instead of if-if-if i did if-if else-if else. which means it will look for alternatives and change the values of the other checks as it cant figure it out.
> 
> thanks. i think you'll see alot of simple stuff that ill post here, just because i overthink everything. if the forum had a thanks or rep button youd get one straight away haha! so thanks man i appreciate the help



No worries. Simple stuff is fine, gotta start somewhere right?

I didn't want to rewrite your code before, just show you why you were only getting 1 of the checks to take effect. But out of curiosity, why not write that checkbox logic this way?


		Code:
	

i private void btnBereken_Click(object sender, EventArgs e)
        {
            int som = 30;
            if (chkBeurs.Checked)
            {
                som -= 5;
            }
            if (chkKamers.Checked)
            {
                som -= 5;
            }
            if (chkActief.Checked)
            {
                som -= 10;
            }
            txtTotaal.Text = Convert.ToString(som);
        }


----------



## M1kkelZR

Cromewell said:


> No worries. Simple stuff is fine, gotta start somewhere right?
> 
> I didn't want to rewrite your code before, just show you why you were only getting 1 of the checks to take effect. But out of curiosity, why not write that checkbox logic this way?
> 
> 
> Code:
> 
> 
> i private void btnBereken_Click(object sender, EventArgs e)
> {
> int som = 30;
> if (chkBeurs.Checked)
> {
> som -= 5;
> }
> if (chkKamers.Checked)
> {
> som -= 5;
> }
> if (chkActief.Checked)
> {
> som -= 10;
> }
> txtTotaal.Text = Convert.ToString(som);
> }



well now that i look at it it would make more sense to actually state the answer in the checkbox and have the calculation take effect in the checkbox if its checked. makes the end line less cluttered in my eyes. 

dont get me wrong im a good programmer for games etc but these simple things just break my balls really. overthinking is just one of the many bad things i have. but as you said gotta start somewhere, and ill start here!


----------



## S.T.A.R.S.

You are a good programmer,but THIS was hard for you???
Wow...and I thought I am weird lol xD


----------



## M1kkelZR

S.T.A.R.S. said:


> You are a good programmer,but THIS was hard for you???
> Wow...and I thought I am weird lol xD



yeah its weird. i can easily make server based games and console's but this just got me by suprise. good thing i can always google but this time google didnt help lol


----------



## spider_007

This is my collide-function, i'm making a space invaders...
It's working, but I want a better function for when they hit each other
(userbullet-enemy) or (enemybullet-user)
one = the bullet of either user/bullet
two = user/enemy
I use this method for checking both.
I'd like a more effective way to calculate if a bullet has reached a player,
some people told me to do it with rectangles, but could anyone give an example of that, please?

thanks, spider



		Code:
	

private bool Collides(Sprite one, Sprite two)
        {
            if (one == null || two == null)
            {
                return false;
            }
            else if
            (
                two.X < one.X
                && (two.X + two.Width) > (one.X + one.Width)
                && two.Y < one.Y
                && (two.Y + two.Height) > (one.Y + one.Height)
            )
            {
                return true;
            }
            else
            {
                return false;
            }
        }


----------



## Cromewell

What you are trying to do with box collision models is draw a box around your objects (player, targets, bullets), then check if the any of the boxes overlap. If so, it's a hit.

From your code snippet, it looks like you are on the right track. Sprites are basically a box already so you just need to see if they overlapped.


----------



## spider_007

Cromewell said:


> What you are trying to do with box collision models is draw a box around your objects (player, targets, bullets), then check if the any of the boxes overlap. If so, it's a hit.
> 
> From your code snippet, it looks like you are on the right track. Sprites are basically a box already so you just need to see if they overlapped.



Yeah I made a Rectangle class and was able to draw them around the players, but the bullets are more difficult and I heard there was a Intersect-method available as well, I just started programming this month, so I'm still at the basic-stuff, 

anyways, thanks for your reply


----------



## Cromewell

There may be something like intersect, I'm not to big on .net. I can read the code, but I don't really know any objects/default methods off hand like I would with Java.

It should be the same to draw a box over the bullet, you just need to move the box with it. You'll want to be careful about speed though, make sure that if the bullet moves so fast that it could pass through another box in a single update that you check the 'hit range.'


----------



## AntimatterAsh

*VB.NET Question*

How can I create a class in Visual Basic .Net 4.5 2010 so that it says something like:


		Code:
	

Private Class Form1
Private Sub Label1.formload()
Lable1.text = ProcessorName()
End Sub
End Class


So that when the form loads, the label's text changes to the processor name like "i3-2330M"


----------



## janrob

Never used VB.NET but in VB6 there is an event called form_load and there you put the start up code.


----------



## AntimatterAsh

janrob said:


> Never used VB.NET but in VB6 there is an event called form_load and there you put the start up code.



I don't think you understand. What I cant find is the command that changes the Label's text to the Processor Name.


----------



## Cromewell

What does your ProcessorName sub/function return?

Also, merged with our .net thread


----------



## AntimatterAsh

Cromewell said:


> What does your ProcessorName sub/function return?
> 
> Also, merged with our .net thread



It doesn't work, I am trying to find a place to start with it


----------



## Cromewell

Ok, well lets start there. Your code to change the label's text is fine, assuming your ProcessorName function returns a string.

Are you trying to read hardware strings to determine the name of the processor? I think something like this will do it.


		Code:
	

moSearch = New Management.ManagementObjectSearcher("Select *
from Win32_Processor")
moReturn = moSearch.Get
For Each mo In moReturn
 sCPManufacturer = mo("Manufacturer").ToString.Trim
 sCPName = mo("Name").ToString.Trim
 sCPSerialNo = mo("ProcessorID").ToString.Trim
next


----------



## AntimatterAsh

Cromewell said:


> Ok, well lets start there. Your code to change the label's text is fine, assuming your ProcessorName function returns a string.
> 
> Are you trying to read hardware strings to determine the name of the processor? I think something like this will do it.
> 
> 
> Code:
> 
> 
> moSearch = New Management.ManagementObjectSearcher("Select *
> from Win32_Processor")
> moReturn = moSearch.Get
> For Each mo In moReturn
> sCPManufacturer = mo("Manufacturer").ToString.Trim
> sCPName = mo("Name").ToString.Trim
> sCPSerialNo = mo("ProcessorID").ToString.Trim
> next



I will try that  Do I put this in as its own sub? It is vb.net right? Would it be better to convert to a C of somesort like C#, C#.net or C++ as I am new to this.#

No...I am guessing that this is C#, as VB.NET gives me loads of errors, if you wait until saturday, I can download C#.NET  Would you be willing to help teach me to use it?


----------



## Cromewell

It should work in VB, Unfortunately, I haven't built this myself as I don't have a vm with a dev environment for .net right now. If you have option explicit on make sure the variables are dim'd.

It's possible that there's an addin module missing from the project, I'll see what I can find, or if there's an alternative.

What errors are you getting?


----------



## AntimatterAsh

Cromewell said:


> It should work in VB, Unfortunately, I haven't built this myself as I don't have a vm with a dev environment for .net right now. If you have option explicit on make sure the variables are dim'd.
> 
> It's possible that there's an addin module missing from the project, I'll see what I can find, or if there's an alternative.
> 
> What errors are you getting?



I have no idea:L I am new and know nothing about what this means. The best I have been able to program is this:
Version 1: http://www.mediafire.com/?8dnav7neq6ll72j
Version 2: http://www.mediafire.com/?zcxrd8skdvnfqnv

Its a disk cleanup...I want to expand on it so it shows CPU usage with a performance bar, RAM usage with a performance bar, the CPU Name, Model, and the amount of RAM.

I know nothing about Visual Basic, I started a week ago, and don't know where to start 

The version 2 crashes on all x86_32 systems it seems, it crashed on all the school computers (which I guess are 32 bit as they used to have XP on, or only have 4gb ram, and had Ubuntu Originally on it.) and my netbook (which is x86_32), and my other Laptop (that is running Windows 7 x86_32, even though it is a x86_64 processor). It only seems to work on my Toshiba which is 64bit, and on Spirit and Smilemans computers, which I guess are 64bit.:angry: Its really frustrating as Version 1 works on them, Version 2 is the same code, but just a different layout of the design, and a code to fade in and out the forms when the value of focus changes. :gun:

Be interesting to know if you have any ideas, as I have exhausted my limited knowledge


----------



## M1kkelZR

Hey guys, I'm doing a programming thing for college in C#. I'm nearly done. I have to use Databindings, DataSources etc and it has to be finished tomorrow.
This is annoying me, I have a picturebox where I import a picture. I save the record but it doesnt save the picture to that record. It keeps the picture for every record. Also when I restart the program the picture doesn't appear.

This is my code now:



		Code:
	

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.IO;

namespace CDForm
{
    public partial class Form1 : Form
    {

        private string fileName = string.Format(@"{0}\teams.xml", Application.StartupPath);

        BindingSource Verzameling = new BindingSource();
        CDverzameling Teamset = new CDverzameling();


        public Form1()
        {
            InitializeComponent();
            MyInitialize();

            backgroundWorker1.RunWorkerAsync();

            Teamset.ReadXml(fileName);
            this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
        }

        void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Verzameling.EndEdit();
            Teamset.WriteXml(fileName);
        }

        private void MyInitialize()
        {

            Verzameling.DataSource = Teamset.Tables["Teams"];

            this.txtTeamName.DataBindings.Add(new Binding("Text", Verzameling, "TeamName"));
            this.txtMember.DataBindings.Add(new Binding("Text", Verzameling, "Member"));
            //this.txtWeapon.DataBindings.Add(new Binding("Text", Verzameling, "Weapon"));
            this.txtSkill.DataBindings.Add(new Binding("Text", Verzameling, "Skill"));
            this.pictureBox1.DataBindings.Add(new Binding("ImageLocation", Verzameling, "Weapon"));
            //this.cmbChooseWeap.DataBindings.Add(new Binding("SelectedValue", Verzameling, "Weapon"));

            this.Teamsbn.BindingSource = Verzameling;
        }

        private void btnToon_Click(object sender, EventArgs e)
        {
            Process.Start("Notepad.exe", fileName);
        }


        private void btnSave_Click(object sender, EventArgs e)
        {
            Teamset.WriteXml(fileName);
        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            this.Activate();
        }

        private void btnForm2_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.Show();
            this.Hide();
        }

        private void picBut_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title = "Choose Gun For Correct Class.";
            dlg.InitialDirectory = "Guns/";

            if (!Directory.Exists(initialDirectory))
            {
                
                if (initialDirectory != "Guns/")
                {
                   // MessageBox.Show("Not the Right Directory. Please Use the Guns folder in this project.");
                    dlg.Dispose();
                }
                else
                {
                    // Do nothing
                }
            }
            
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.pictureBox1.Image = new Bitmap(dlg.OpenFile());
            }
            dlg.Dispose();
        }

        public string initialDirectory { get; set; }
    }
}


Basically I just need help to save the image and change for each record. So if anyone can help that would be awesome


----------



## Cromewell

M1kkelZR said:


> Hey guys, I'm doing a programming thing for college in C#. I'm nearly done. I have to use Databindings, DataSources etc and it has to be finished tomorrow.
> This is annoying me, I have a picturebox where I import a picture. I save the record but it doesnt save the picture to that record. It keeps the picture for every record. Also when I restart the program the picture doesn't appear.
> 
> This is my code now:
> 
> 
> 
> Code:
> 
> 
> using System;
> using System.Collections.Generic;
> using System.ComponentModel;
> using System.Data;
> using System.Drawing;
> using System.Linq;
> using System.Text;
> using System.Windows.Forms;
> using System.Diagnostics;
> using System.Threading;
> using System.IO;
> 
> namespace CDForm
> {
> public partial class Form1 : Form
> {
> 
> private string fileName = string.Format(@"{0}\teams.xml", Application.StartupPath);
> 
> BindingSource Verzameling = new BindingSource();
> CDverzameling Teamset = new CDverzameling();
> 
> 
> public Form1()
> {
> InitializeComponent();
> MyInitialize();
> 
> backgroundWorker1.RunWorkerAsync();
> 
> Teamset.ReadXml(fileName);
> this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
> }
> 
> void Form1_FormClosing(object sender, FormClosingEventArgs e)
> {
> Verzameling.EndEdit();
> Teamset.WriteXml(fileName);
> }
> 
> private void MyInitialize()
> {
> 
> Verzameling.DataSource = Teamset.Tables["Teams"];
> 
> this.txtTeamName.DataBindings.Add(new Binding("Text", Verzameling, "TeamName"));
> this.txtMember.DataBindings.Add(new Binding("Text", Verzameling, "Member"));
> //this.txtWeapon.DataBindings.Add(new Binding("Text", Verzameling, "Weapon"));
> this.txtSkill.DataBindings.Add(new Binding("Text", Verzameling, "Skill"));
> this.pictureBox1.DataBindings.Add(new Binding("ImageLocation", Verzameling, "Weapon"));
> //this.cmbChooseWeap.DataBindings.Add(new Binding("SelectedValue", Verzameling, "Weapon"));
> 
> this.Teamsbn.BindingSource = Verzameling;
> }
> 
> private void btnToon_Click(object sender, EventArgs e)
> {
> Process.Start("Notepad.exe", fileName);
> }
> 
> 
> private void btnSave_Click(object sender, EventArgs e)
> {
> Teamset.WriteXml(fileName);
> }
> 
> private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
> {
> this.Activate();
> }
> 
> private void btnForm2_Click(object sender, EventArgs e)
> {
> Form2 f2 = new Form2();
> f2.Show();
> this.Hide();
> }
> 
> private void picBut_Click(object sender, EventArgs e)
> {
> OpenFileDialog dlg = new OpenFileDialog();
> 
> dlg.Title = "Choose Gun For Correct Class.";
> dlg.InitialDirectory = "Guns/";
> 
> if (!Directory.Exists(initialDirectory))
> {
> 
> if (initialDirectory != "Guns/")
> {
> // MessageBox.Show("Not the Right Directory. Please Use the Guns folder in this project.");
> dlg.Dispose();
> }
> else
> {
> // Do nothing
> }
> }
> 
> if (dlg.ShowDialog() == DialogResult.OK)
> {
> this.pictureBox1.Image = new Bitmap(dlg.OpenFile());
> }
> dlg.Dispose();
> }
> 
> public string initialDirectory { get; set; }
> }
> }
> 
> 
> Basically I just need help to save the image and change for each record. So if anyone can help that would be awesome


I see you binding the image but does your database have the appropriate storage types to handle an image?


AshleyScopes said:


> I have no idea:L I am new and know nothing about what this means. The best I have been able to program is this:
> Version 1: http://www.mediafire.com/?8dnav7neq6ll72j
> Version 2: http://www.mediafire.com/?zcxrd8skdvnfqnv
> 
> Its a disk cleanup...I want to expand on it so it shows CPU usage with a performance bar, RAM usage with a performance bar, the CPU Name, Model, and the amount of RAM.
> 
> I know nothing about Visual Basic, I started a week ago, and don't know where to start
> 
> The version 2 crashes on all x86_32 systems it seems, it crashed on all the school computers (which I guess are 32 bit as they used to have XP on, or only have 4gb ram, and had Ubuntu Originally on it.) and my netbook (which is x86_32), and my other Laptop (that is running Windows 7 x86_32, even though it is a x86_64 processor). It only seems to work on my Toshiba which is 64bit, and on Spirit and Smilemans computers, which I guess are 64bit.:angry: Its really frustrating as Version 1 works on them, Version 2 is the same code, but just a different layout of the design, and a code to fade in and out the forms when the value of focus changes. :gun:
> 
> Be interesting to know if you have any ideas, as I have exhausted my limited knowledge


Sorry I meant to look at this earlier but forgot. I'll try to get to it when I get home. I can't get on mediafire here.


----------



## M1kkelZR

Yeah I've got the attribute to use an Image and the ImageLocation. Now it saves the picture in the record but when I start it up again it deletes it. Also can't change to a different picture because it changes it on every record lol. No clue whats going on

EDIT: Never mind, I figured it out  I forgot about the whole "It needs to write a path to the XML database" part


----------



## Cromewell

AshleyScopes said:


> I have no idea:L I am new and know nothing about what this means. The best I have been able to program is this:
> Version 1: http://www.mediafire.com/?8dnav7neq6ll72j
> Version 2: http://www.mediafire.com/?zcxrd8skdvnfqnv
> 
> Its a disk cleanup...I want to expand on it so it shows CPU usage with a performance bar, RAM usage with a performance bar, the CPU Name, Model, and the amount of RAM.
> 
> I know nothing about Visual Basic, I started a week ago, and don't know where to start
> 
> The version 2 crashes on all x86_32 systems it seems, it crashed on all the school computers (which I guess are 32 bit as they used to have XP on, or only have 4gb ram, and had Ubuntu Originally on it.) and my netbook (which is x86_32), and my other Laptop (that is running Windows 7 x86_32, even though it is a x86_64 processor). It only seems to work on my Toshiba which is 64bit, and on Spirit and Smilemans computers, which I guess are 64bit.:angry: Its really frustrating as Version 1 works on them, Version 2 is the same code, but just a different layout of the design, and a code to fade in and out the forms when the value of focus changes. :gun:
> 
> Be interesting to know if you have any ideas, as I have exhausted my limited knowledge



I can't look through the code in those exes but my guess is the compile method is the problem. If they are compiled for a particular architecture, ie x86-64, it won't work on a 32 bit system. A 32 bit compiled version should work on either version of windows.


----------



## S.T.A.R.S.

AshleyScopes said:


> I have no idea:L I am new and know nothing about what this means. The best I have been able to program is this:
> Version 1: http://www.mediafire.com/?8dnav7neq6ll72j
> Version 2: http://www.mediafire.com/?zcxrd8skdvnfqnv
> 
> Its a disk cleanup...I want to expand on it so it shows CPU usage with a performance bar, RAM usage with a performance bar, the CPU Name, Model, and the amount of RAM.
> 
> I know nothing about Visual Basic, I started a week ago, and don't know where to start
> 
> The version 2 crashes on all x86_32 systems it seems, it crashed on all the school computers (which I guess are 32 bit as they used to have XP on, or only have 4gb ram, and had Ubuntu Originally on it.) and my netbook (which is x86_32), and my other Laptop (that is running Windows 7 x86_32, even though it is a x86_64 processor). It only seems to work on my Toshiba which is 64bit, and on Spirit and Smilemans computers, which I guess are 64bit.:angry: Its really frustrating as Version 1 works on them, Version 2 is the same code, but just a different layout of the design, and a code to fade in and out the forms when the value of focus changes. :gun:
> 
> Be interesting to know if you have any ideas, as I have exhausted my limited knowledge



To read informations from the hardware like amount of RAM,CPU name,model and everything else you would like,I recommend you to use Managed Object Searcher class.
Of course you will need to add the following namespace:

using System.Management;

Here is an example of getting the total amount of RAM in bytes:

ManagementObjectSearcher mos1=new ManagementObjectSearcher("SELECT * FROM WIN32_PHYSICALMEMORY");
foreach(ManagementObject mo1 in mos1.Get())
{
      MessageBox.Show(mo1.GetPropertyValue("CAPACITY").ToString());
}



By the way I am SOOOOO bored right now lol xD


----------



## WeatherMan

I'm making an application for a software development class and really behind right now.

Got the design done, but can't figure out the code!

Here is what I have done so far:





Could someone assist me with some code for multiplying the 'Cost' (Label) by the 'Quantity' (Combobox) so that the £VALUE is entered into the Total column, which is a label.

Thanks


----------



## Cromewell

Probably something like this: CType(Combobox.SelectedValue, Integer) * CType(Label.Text, Double)


----------



## M1kkelZR

ey guys, I'm getting an error when I want t add a file to my dataGridView that I can't add any data because it is databound. I've been working around this but still gives me the same error. heres the snippet of the code:



		Code:
	

SQLiteDataAdapter dAdapter = new SQLiteDataAdapter();
        SQLiteConnection connect = new SQLiteConnection("Data Source=C:/Users/Michael/Desktop/TestingSQL3/TestingSQL3/test.s3db");
        BindingSource bSource = new BindingSource();
        DataTable dTable = new DataTable();




		Code:
	

  private void btnOpenLog_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
            {
                String sLine = "";
                try
                {
                    System.IO.StreamReader FileStream = new System.IO.StreamReader(openFileDialog1.FileName);
                    sLine = FileStream.ReadLine();
                    string[] s = sLine.Split(';');
                    for (int i = 0; i <= s.Count() - 1; i++)
                    {
                        DataGridViewColumn colHold = new DataGridViewTextBoxColumn();
                        colHold.Name = "col" + System.Convert.ToString(i);
                        colHold.HeaderText = s[i].ToString();
                        dataGridView1.Columns.Add(colHold);
                    }
                    sLine = FileStream.ReadLine();
                    while (sLine != null)
                    {
                        dataGridView1.Rows.Add();
                        for (int i = 0; i <= s.Count() - 1; i++)
                        {
                            s = sLine.Split('|');
                            dataGridView1.Rows[dTable.Rows.Count - 1].Cells[i].Value = s[i].ToString();
                        }
                        sLine = FileStream.ReadLine();
                    }
                    FileStream.Close();
                }
                catch (Exception err)
                {
                    System.Windows.Forms.MessageBox.Show("Error:  " + err.Message, "Program Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }


If anyone can help me with anything would be cool.


----------



## AntimatterAsh

Using Visual Basic.NET in Visual Studio Express 2010...

Can some one help instruct me on how to construct a function that can get me details about my PSU, and Video Card, I want to use that function in the Form1_Load code to change a label (i.e. Label1.text = GPUName()) to each spec that I am able to give, I do not know where to start, I have already developed how to get CPU threads and Usage, and Memory Usage but this is from the registry and I do not know how to use anything like WMI and make it work...I dont know where to start -.- I only started learning a few weeks ago :/

Cheers for any help!

(If you want to have a look what I have done, its the most recent post here: http://ashleystechtalk.blogspot.co.uk/p/aperture-science-release-log.html )

Ash


----------



## M1kkelZR

Well I have a thing where I can get the name of the GPU etc, which is easy. Just look for WMI Controls (a nice example: http://www.dotnetheaven.com/article/windows-management-instrumentation-in-vb.net) For usage I need to figure out, I do use C#.net so I wont be able to help with VB.net but as far as I've seen its pretty much the same.

Here my Example of the WMI in c#:
A using declaration:


		Code:
	

using System.Management;


So you'll need a searcher, so use this:



> ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * from Win32_VideoController");


This gets the Name of the GPU, at the moment I'm at work so it would say GeForce 9300 GE.

Now you want to change the Label name to say GeForce 9300 GE (or whatever GPU you have installed) 


		Code:
	

            foreach (ManagementObject gpuObj in searcher.Get())
            {
                lblGPU.Text = (gpuObj["VideoProcessor"].ToString());
            }

This is all C# but its basically the same in VB.net. I'm still trying to figure out how I can get some clock speeds etc to show and a way to get the GPU/CPU/RAM usage + voltage/wattage on each component.

Hope I helped a little if not, then just use the delete button in your brain and get rid of this knowledge


----------



## AntimatterAsh

M1kkelZR said:


> Well I have a thing where I can get the name of the GPU etc, which is easy. Just look for WMI Controls (a nice example: http://www.dotnetheaven.com/article/windows-management-instrumentation-in-vb.net) For usage I need to figure out, I do use C#.net so I wont be able to help with VB.net but as far as I've seen its pretty much the same.
> 
> Here my Example of the WMI in c#:
> A using declaration:
> 
> 
> Code:
> 
> 
> using System.Management;
> 
> 
> So you'll need a searcher, so use this:
> 
> 
> This gets the Name of the GPU, at the moment I'm at work so it would say GeForce 9300 GE.
> 
> Now you want to change the Label name to say GeForce 9300 GE (or whatever GPU you have installed)
> 
> 
> Code:
> 
> 
> foreach (ManagementObject gpuObj in searcher.Get())
> {
> lblGPU.Text = (gpuObj["VideoProcessor"].ToString());
> }
> 
> This is all C# but its basically the same in VB.net. I'm still trying to figure out how I can get some clock speeds etc to show and a way to get the GPU/CPU/RAM usage + voltage/wattage on each component.
> 
> Hope I helped a little if not, then just use the delete button in your brain and get rid of this knowledge



All of it just gives errors :/ System.Management is a namespace and not a expression one says and then searcher needs to be inside parenthesis or whatever :/ cheers anyway, dont think I'm gonna be able to do it :/


----------



## M1kkelZR

AshleyScopes said:


> All of it just gives errors :/ System.Management is a namespace and not a expression one says and then searcher needs to be inside parenthesis or whatever :/ cheers anyway, dont think I'm gonna be able to do it :/



I did say it is C#.net, the base is the same. Here a few links for VB.net and WMI etc:
http://www.freevbcode.com/ShowCode.asp?ID=4571
http://www.codeproject.com/Questions/292691/Help-with-wim-vb-net-coding
http://vbcity.com/forums/t/70161.aspx
http://www.emmet-gray.com/articles/wmi_intro.htm

most of it is the same but some explained differently.


----------



## AntimatterAsh

What other things can I add for computer info? Its VB.NET so any ideas are appreciated


----------



## M1kkelZR

AshleyScopes said:


> *snip*
> 
> What other things can I add for computer info? Its VB.NET so any ideas are appreciated



you could include a HDD read/write speed reader for current movements etc. Fan Speeds for fans you have.

All you need to do is just think of stuff you would want to see in your program


----------



## AntimatterAsh

M1kkelZR said:


> you could include a HDD read/write speed reader for current movements etc. Fan Speeds for fans you have.
> 
> All you need to do is just think of stuff you would want to see in your program



How would I do that?

I have only properly been teaching myself VB.NET for 2 weeks


----------



## M1kkelZR

AshleyScopes said:


> How would I do that?
> 
> I have only properly been teaching myself VB.NET for 2 weeks



there is a whole world of codez on the internetz, but because this is hardware based everything is used with the WMI.
Just have a google around for some tutorials and stuff for WMI.

I also found this: WMI Code Creator, maybe its worth looking at


----------



## AntimatterAsh

*Visual Basic Question*

In VB.NET, how would I say:



		Code:
	

if CPUPercent.text = "0%" to "10%" then
CPUPercent.fontcolor = red
end if
if CPUPercent.text = "11%"-"20%"
then ...


You get the picture. I have used a code to produce a CPU usage percentage, and I want it to change colour as the CPU usage percentage raises. The answer to the % processor time query is set as a text answer though.

What I have so far is:




It is basically a small widget that sits on the desktop that is trained to monitor CPU and RAM performance for my Server.


----------



## AntimatterAsh

New update to ^^^

Can some people on here quickly test this for me to make sure it works properly (read the post first).


----------



## bradleyhand

Hi guys I'm doing a computer project in school.

It is just to create a website. I have used basic html and js, and I wanted to use basic ASPX too in some areas like reading user inputs, mainly because i want to use a WEB FORM. ASPX has been taught by my lecturers and I should use it to get higher marks in my project. So I decided to use it.

I have problems With ASPX.NET in *My Microsoft VS.*
It only works when I open it with visual studio and from there, I click this 'view in browser' option, which directs to my browser. The Content are like labels and textboxes and dropdownlists.

However it does not work properly (but it runs) when I open the aspx file from the file folder (finding the directory of the aspx file and opening it with 'open with..').
it runs, but it prints the first line which it should not
The first line is: 

<%@ Page Language="C#" AutoEventWireup="False" Codebehind="Default2.aspx.cs" Inherits="Default2" %>

It also prints words if I just type below the first line. It is seems to be acting like a HTML file.
What should I do now?

when I use the computers in school which have Microsoft VS, it works.
But mine doesn't.

Maybe I didn't downloaded it properly. My friends say that even if I download VS, I would have to download some other stuff. Idk im not sure abt this just saying if it has got to  do with my problem. 

Pls Help! This is important! My Project Is due next Monday and i do not want to have bad results! and sory if  my English grammer and sentence constructions are bad. i'm not a language person.. >.<

ty


----------



## Cromewell

I don't know how your computers at school are set up but if you don't have a webserver hosting your project (with .NET framework configured), opening the asp/aspx file won't work. Starting VS and telling it to view project starts up a temporary webserver with everything it needs.

Also, moved to the correct thread


----------



## bradleyhand

so is this NET framework a webserver? Do I download it like downloading java? I just want my webform to work!

ty

O yeah I think I have Netframework 4 when I try to create a webform in VS, so do I download 4.5? o yeah and I did not use the Visual Studio for my project at first bcause I didn't download it. I use my notepad because I thought I just had to use css html and js until when the lecture said abt the aspx thingy then I had no idea how to do it with basic tools. then my classmates helped me to download the visual studio IDE. So basically.. I have my files in just a random folder. It is not like a Microsoft visual studio project. So when I make an aspx file, I just copy paste the aspx and aspx.cs into that random folder. Is this alright? am I doing things wrong?

tyty

edited: hey I tried downloading 4.5 and windows said that I already have it. mayb bcause im using windows8.
edited:Hi administrator, is that a job?


----------



## bradleyhand

hi administrator,
I have consulted a friend and now I have a clearer idea on what u meant.
Now I have a real problem.
with this error message that I did not get last time when I used the webform.
"
This page contains the following errors:

error on line 1 at column 2: StartTag: invalid element name
Below is a rendering of the page up to the first error.
"


----------



## Cromewell

It sounds like you've probably got some server configuration to do yet.

You already have the .NET framework installed, so that part is good. The second part of the problem is having a webserver configured to use it. I have stood one up with duct tape and bubble gum 

Basically, you go to Add/Remove Programs -> Add Windows Components -> find IIS (internet information services) and install it.

Then there's some monkeying around to the default website (this is the duct tape and bubblegum part) to tell it what framework to run applications with, and you add your project as an application. From what I remember, it's a lot of going in and out of GUI elements from the IIS management console.


----------



## bradleyhand

i cant add it but i have gotten it in one of my windows features. So i on this IIS, and most of its components but i still got that error! Any advice>?
tyty
O i just realized that in IE by aspx file does not show the above error, just blank page. Except when im using google chrome, error is shown.

If this don't work.. I think i'll have no choice but to stop using aspx for my project. 
bye bye A.
thanks anyways for helping alot.
tyty

Hey i just made a virtual directory in iis in my file folder. Will tell u if it worked out!

.......didn't


----------



## Cromewell

In the IIS management console, there should be an option for a new application under your website. That's the one you want to make.


----------



## bradleyhand

ty


----------



## SpriteMidr

Is there any way to get the current CPU clock speed (variable, not maximum) for the system I am using in C♯?

I am currently using the following



		Code:
	

using System;
using System.Threading; // Sleep
// Add reference to following
using System.Management;

static class App {
  static void Main(string[] args) {
    // WMI query
    const string WQL_QUERY = "SELECT DeviceID, Name, CurrentClockSpeed FROM Win32_Processor;";
   
    var wmiSearcher = new ManagementObjectSearcher(WQL_QUERY);
   
    // Perform in a loop.
    while(true) {
      // Set cursor position to 0,0 (quicker to overwrite than to clear)
      Console.SetCursorPosition(0,0);

      // Perform search, store results (each CPU available) in a ManagementObjectCollection
      ManagementObjectCollection resultCollection = wmiSearcher.Get();

      // For each result
      foreach(ManagementObject result in resultCollection) {
        var device = result["DeviceID"].ToString();
        var name = result["Name"].ToString();
        var speedSz = result["CurrentClockSpeed"].ToString();
        var speed = uint.Parse(speedSz);
       
        // Output result
        App.FormatOutput(device, name, speed);
      }
      // Wait two seconds
      Thread.Sleep(2000);
      continue; // (not needed, but useful notation for this example, hence why it is included).
    }
  }

  private static void FormatOutput(string device, string name, uint speed) {
    Console.Out.WriteLine("{0} ({1}) is running at {0,5} MHz.", device, name, speed);
  }
}

Link to working code on Github

The code above is dumbed down to just printing to the console. My actual app is graphing the result (hence the link), so the code is a bit more complex, but uses the same principle.

I just feel that performing a SQL (well, WQL) query every two seconds is a bit stupid. It is a complex operation, so it keeps making the clock speed spike whenever it executes.

Any ideas are welcome 

Thanks


----------



## Cromewell

Try CurrentClockSpeed.

You can see what's available by looking at Win32_Processor: https://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx


----------



## SpriteMidr

Cromewell said:


> Try CurrentClockSpeed.
> 
> You can see what's available by looking at Win32_Processor: https://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx





		Code:
	

const string WQL_QUERY = "SELECT DeviceID, Name, CurrentClockSpeed FROM Win32_Processor;";


WQL is horribly slow though. It would be nice to have access to the system that WMI uses to get that info. I mean, performance counter supports processor time, so there must be an API somewhere.


----------



## Cromewell

Sorry, didn't read all your code the first time, I just saw the question and assumed you were using MaxClockSpeed.

HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\# has the MHz speed, but  I'm pretty sure that's the max speed.

I wasn't able to find anything C# besides the WMI documentation. As you mentioned the PerformanceCounters don't show quite what you are looking for.

I found someone who's implemented it in a very short assembly program but I don't know of a way to run assembly from c# (c/++ is another story )


----------



## SpriteMidr

Cromewell said:


> Sorry, didn't read all your code the first time, I just saw the question and assumed you were using MaxClockSpeed.
> 
> HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\# has the MHz speed, but  I'm pretty sure that's the max speed.
> 
> I wasn't able to find anything C# besides the WMI documentation. As you mentioned the PerformanceCounters don't show quite what you are looking for.
> 
> I found someone who's implemented it in a very short assembly program but I don't know of a way to run assembly from c# (c/++ is another story )



In C#, can you use a compiled DLL? iirc there is an extern command, as you can use the Win32 API, and that is not dotnet.

In C/C++ I believe there is an Assembly module, so could I use the assembly module to interface with it in C and then compile down to a DLL that I can implement in C#?

Or am I talking garbage?


----------



## Cromewell

Yeah in C you can use asm (assembly instructions).

You can call to dlls in c# but I don't have experience doing that. I can look it up and help if you have trouble with it, but at that point we're doing the same thing


----------



## SpriteMidr

Cromewell said:


> Yeah in C you can use asm (assembly instructions).
> 
> You can call to dlls in c# but I don't have experience doing that. I can look it up and help if you have trouble with it, but at that point we're doing the same thing



Ah okydokes 

 I might look into it more after my exams are over.

Thanks again for the help! Appreciate it.


----------



## SpriteMidr

Cromewell said:


> Yeah in C you can use asm (assembly instructions).
> 
> You can call to dlls in c# but I don't have experience doing that. I can look it up and help if you have trouble with it, but at that point we're doing the same thing



Been having a fiddle with the cpuid instruction in assembly (had to use C, not C#, but I thought I might as well post the general idea just in case anyone else wants to know)... seems you can get most of the info from WMI in C using inline Assembly.

The following prints either GenuineIntel or AuthenticAmd depending on your cpu...



		Code:
	

#include <Windows.h>
#include <stdio.h>

/*
 * Get the CPU vendor ID.
 * out - a 13 byte long char buffer to fill.
 */
void getVendorId(char* output) {
  DWORD b, c, d; // 4 byte integer

  __asm {
    mov eax, 0x0 // Move the eaxVal param to eax
    cpuid           // call cpuid op
    mov b, ebx
    mov c, ecx
    mov d, edx
  };

  // Use char buffers for each integer value to abstract the int
  char bBuff[4], cBuff[4], dBuff[4];

  // Copy data to buffers
  memcpy(bBuff, &b, 4);
  memcpy(cBuff, &c, 4);
  memcpy(dBuff, &d, 4);

  // Concatenate the char buffers for each register to one string
  static char buff[13];

  int i;
  // Copy the buffer contents over. Remembering that
  // each buffer is NOT null terminated, so we don't 
  // want to buffer overflow.
  for (i = 0; i < sizeof(buff); ++i) {
    if (i >= 0 && i <= 3)
      buff[i] = bBuff[i % 4];
    else if (i > 3 && i <= 7)
      buff[i] = dBuff[i % 4];
    else if (i > 7 && i <= 11)
      buff[i] = cBuff[i % 4];
    else
      buff[i] = NULL;
  }

  // Copy the buffer to output
  strcpy_s(output, 13, buff);
}

int main() {
  char vendorId[13];
  getVendorId(vendorId);
  printf("Vendor ID: %s\n", vendorId);
  gets(stdin);
}


(Compiled using Visual C)

<edit: improved code readability>


----------



## Cromewell

I just found this. it's the SDK for what CPUz uses. http://www.cpuid-pro.com/products-services.php and is available for C#. Looks like it's payware though...

That being said, since they've written it, there must be a way


----------

