CodeDoctor 0 Light Poster

How do you want to store the array? CSV? XML? Binary?

Another great .NET technique is to understand and implement Object Serialization. Here is an example:
Import the following namespace:

Imports System.Runtime.Serialization.Formatters.Binary

Create a new Structure:

<Serializable()> Public Structure Person
       Dim Name As String
       Dim Age As Integer
       Dim Income As Decimal
   End Structure

Now, create an instance of this structure and populate it.
Write it to your file:

P = New Person()
   P.Name = "Joe Doe"
   P.Age = 35
   P.Income = 28500
   BinFormatter.Serialize("c:\MyFile.txt", P)
FS = New System.IO.FileStream _
      ("c:\MyFile.txt", IO.FileMode.OpenOrCreate)
   Dim obj As Object
   Dim P As Person()
   Do
       obj = BinFormatter.Deserialize(FS)
       If obj.GetType Is GetType(Person) Then
           P = CType(obj, Person)
           ' Process the P objext
       End If
   Loop While FS.Position < FS.Length - 1
   FS.Close()

The object P object will now contain the Person object you serialized previously.


Hope this helps.

CodeDoctor 0 Light Poster

What if I am not using the User-Control to communicate back?
What if I am using the User-Control as the form itself and using the actual form as a container for the User-Control to be placed?

Do I still need events or will I just use functions and subs?

Well, the answer is NO, you don't need events if you are only creating code procedures in your main form. You can simply call those procedures.

I was trying to show the concept of encapsulation of a User Control. Encapsulating what is needed to be done seperately from your main form. Have your control contain all of that logic, and simply communicate back to your Implementing form through events of the actions your control is taking.

This is an Object Oriented approach to your problem, not a code based approach.


Hope this Helps.

CodeDoctor 0 Light Poster

this is my code

If Me.txtOldPassword.Text = pwd Then
                Dim oledbcom1 As New OleDb.OleDbCommand
                oledbcom1.CommandText = "Update login Set password = ?"

                oledbcom1.Connection = oledbcon

                oledbcom1.Parameters.Add("?", OleDb.OleDbType.VarChar)
                oledbcom1.Parameters(0).Value = Me.txtNewPassword.Text.Trim

                oledbcom1.ExecuteNonQuery()

                oledbcon.Close()
end if

I am going to suggest you name the params.

Ex:

oledbcom1.CommandText = "Update login Set password = @Password"

                oledbcom1.Parameters.Add("@Password", OleDb.OleDbType.VarChar).Value = Me.txtNewPassword.Text.Trim

Hope this Helps...

CodeDoctor 0 Light Poster

Hi;
I am new to VB.net and am developing a memory quiz. The quiz contains more than 100 questions imported from access 2002 db. For the learning process, I need to run the game again and again. At the moment, I can't randomize the question order, I am getting the questions in same sequence as they are taken from db. Could nebody give me some idea, how can I pint to different tb records.
My application has a timer for maintaining question timings. I would like to know where in the function I could utilize the randomize function.
Code is

Public Function rungame()
        Try
            If t <= totq - 1 Then
                ' totq is total no of questions
                ' t is row of table
                Timer1.Enabled = True
                If con.State = ConnectionState.Open Then con.Close()
                con.Open()
                Dim adp As New OleDbDataAdapter("select * from tb2", con)
                Dim ds As New DataSet
                adp.Fill(ds)
                Dim dt As DataTable
                dt = ds.Tables(0)
                qbox.Text = dt.Rows(t).Item(1)
                PictureBox1.ImageLocation = dt.Rows(t).Item(2)
                PictureBox2.ImageLocation = dt.Rows(t).Item(3)
                PictureBox3.ImageLocation = dt.Rows(t).Item(4)
                PictureBox4.ImageLocation = dt.Rows(t).Item(5)
                t = t + 1
                con.Close()
            Else
                Timer1.Enabled = False
                qbox.Text = "Match the given TEXT with the correct IMAGE option"
                optiona.Text = "Option A"
                optionb.Text = "Option B"
                optionc.Text = "Option C"
                optiond.Text = "Option D"
                Button1.Enabled = True
                MsgBox("Thanks for Participation : " & namebox.Text      & "Your score is : " & scorebox.Text, MsgBoxStyle.Information, "Completed")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Function

The code for timer is

Private Sub …
CodeDoctor 0 Light Poster

Dear Members,

Please Help Me. I am in huge problem. Please Send a solution of this problem.

problem is:- Read Table of Word File and take cell value and store in excel file using vb.net in VB

Please Help me............

thanks
Requesmd

Working with Word is not as difficult as you may think. You have to use Automation or VSTO (Visual Studio Tools for Office).

Either way, this can be done quite simply. Here is a COM example of opening Word and accessing the tables within the document.

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/06ecdc92-ea5c-4067-b365-9ed074e0fd86

You can easily search for populating an Excel Workbook with any type of data to fullfill your requirement.

Hope this helps.

CodeDoctor 0 Light Poster

I want to after clicking on button2,after that if i click on button1 then msg is not displayed

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("sonia")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        RemoveHandler Button2.Click, AddressOf MYEVENTHandler
    End Sub

    Private Sub MYEVENTHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class

In your Form Load, setup the event handler for Button1. So, remove the statement Handles Button1.Click at the end of the Button1.Click procedure.

In your Form_Load place the following:
Addhandler Button1.Click, AddressOf MYEVENTHandler

In your MYEVENTHandler place the following code:
msgbox ("sonia")

In the Button2_Click, use the existing code you have, it will work.

Hope this helps.

CodeDoctor 0 Light Poster

@Sknake-I understand thank you

@CodeDoctor - Thank you for replying.

From the post of CodeDoctor, what is the difference of these two codes(Code1 and Code2)?

Sample Code1:

Public Event Show(ByVal myMessage As String)

    Private Sub Message(ByVal myMessage As String) Handles Me.Show
        MsgBox(myMessage)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        RaiseEvent Show("Hello")
    End Sub

Sample Code2:

Private Sub Message(ByVal myMessage As String)
        MsgBox(myMessage)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Message("Hello")
    End Sub

If you are creating a control, and place that control in a place to implement its functionality, this is where you will use Events.

When using code behind in a form, there is no real need to declare an Event for that, you will have access to all of the private/friend/public methods and functions contained within that form.

Always keep in mind that a control is a seperate unit of work, and should be designed as such. If your control need to communicate back to where it is being used, do this through events.

Hope this helps.

CodeDoctor 0 Light Poster

my friends suggest to use the nokia phones to get the data from the inbox and i heard only java can do that type this operationon nokia ..? is that true and please send the java code too if u have tat

No, the Windows Mobile toolkit can help you with any SMS application. Any mobile device can be accessed through this API.

CodeDoctor 0 Light Poster

sorry im making another post but i cant edit my old one:P

but i decided agaisnt xml and now using ini files with something called Nini


if someone can help me with whenever someone clicks the text it then combo box it corresponds to whatever folder or program that text is linked to and i also need help with the combo box taking its items list from the ini file

and here is the code for the ini file

; This is where all the configurations are.
; Dont delete this file or the program will stop working
[Logging]
File Name = USB Launcher.log
MessageColumns = 5
MaxFileSize = 4000000
[Folders]
List = C:\
[Programs]
List =

You can use INI files, however, you can take care of this in a few different ways you will find is a lot easier.

One way is to create a custom Object that represents the unit of work you are trying to accomplish.

This object will have all of the properties and methods for dealing with the configuration information you want to persist to a file. Simply put an attribute at the top of your class like the following:
<Serializable()> _
Public Class1

This will allow serialization of this object. You can do a search on the web for serializing objects to and from files.

Another perhaps easier way, is to use a Dataset.

In a dataset, you can create one or …

CodeDoctor 0 Light Poster

How can I extract repeated paragraphs of data from an html document. Every paragrahp is preceded by the line:
<p><i>Summary as passed House:</i> <br>

Thanks.

You can obtain all Paragraph tags using the WebBrowser control using the following technique:

Dim oElements as HtmlElementCollection
oElements = WebBrowser1.Document.GetElementsByTagName("p")
For each oElement as HtmlElement in oElements
     if oElement.InnerHtml.Contains("<i>Summary as passed House:</i>") then
        debug.print "FOUND"
     end if
Next

You can parse the rest to get the specific data within the <P> tags
Hope this helps.

CodeDoctor 0 Light Poster

How do I use the User-Controls as a form within a Form?

This is my answer to my problem located on this thread

As seen in the original thread's solution, I've used solution #2. Instead of switching forms, I've used switching panels and the controls are contained in those panels. This way, there will be no fade transition between forms. I found this solution a bad practice and becomes unmanageable due to the number of controls in the Design window.

As I've read on CodeDoctor's post , I have found another way of switching Forms within a Form and actually be manageable in terms of OOP design.

Proposed Solution: Use User-Controls as the new panel, "A Form within A Form". In this method I can switch between forms without actually switching the form just the User-Control.

Does anyone have a simple tutorial for newbies using User Control?. Or anyone can just reply with a step by step instruction?

User Controls you will find are easy to create, and a very modular way of creating individual pieces of functionality.

Within your VS 2008 Solution, right click on the project, and choose Add / User Control.

The designer will show a blank design surface that is sizable. Drop any controls you want to on this area.

This example will create a Logon control.
Add two labels with text properties of "Logon:" and "Password:"
Add two text boxes named txtLogon and txtPassword.

CodeDoctor 0 Light Poster

Hi Friends,
This is Srinivas. I developed an application n it requires a picture box to be moved over another. When i wrote the code n moved it over another,the latter picture box(only the part on which the former one moves) is fading and black color is getting displayed! Plzzzzz help me. I want the original picture box not to get affected.

Once the picture boxes is moved over, you can set the Opacity of that picture box to .0

To show the picture box, you can set the Opacity to 1.0

Hope this helps.

CodeDoctor 0 Light Poster

Hi all,

I am doing a project on the CRM application which sending and receiving sms using the vb.net language. I am no where to conclusions of my project because I could not build the application. I have found many examples but the problem some of the examples some uses the sms gateway or the AT commands. I could not differentiate which one to use? I have a dateline to finish this project of mine. Hope that anyone could help me. Most of the example does not look like a CRM application.

Thanks

Regards
LiL_Is

Without having any background on your project, I can only assume you are only interested in sending Text messages. If recieving these messages within your app is needed, you should look at the Windows Mobile framework. There are emulators you can use to act as an SMS gateway.

You can get started with this at : http://geekswithblogs.net/lvega/archive/2008/01/07/118332.aspx

Hope this helps.

CodeDoctor 0 Light Poster

Hello,
My name is Josh I am in college and I am taking Intermediate VB.Net 2008 and I have been doing ok until now. I have been working on this problem for 2 weeks and still can not get it to do what it is suppose to do and it was suppose to be turned in last week. I do have a way to make it work but it doesn`t follow the guidelines and I would really like to learn what I am doing wrong here. So if anyone could help me it would be greatly appreciated it.
Here is the problem. I have a text file (MEMBERPHONES.TXT) the names and phone numbers from this text file should be read into an array of structures, and the names should be displayed in a list box when the form is loaded. There is a lot more instructions for this program that I already have figured out but this part has me stumped. Here is what I have so far PLEASE HELP and thank you in advance for looking at it.

Structure phone
        Dim name As String
        Dim phoneNum As Integer
    End Structure

    Dim phone1() As phone
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sw As IO.StreamWriter = IO.File.CreateText("MEMBERPHONES.TXT")
        sw.WriteLine("Langley, Judy")
        sw.WriteLine("321-1111")
        sw.WriteLine("Morgan,Fred")
        sw.WriteLine("222-2222")
        sw.WriteLine("Nixon, Mike")
        sw.WriteLine("333-3333")
        sw.WriteLine("Norton, Herbert")
        sw.WriteLine("444-4444")
        sw.WriteLine("Preiss, Carol")
        sw.WriteLine("555-5555")
        sw.WriteLine("Ree, Alice")
        sw.WriteLine("666-6666")
        sw.WriteLine("Sanchez, Carlos")
        sw.WriteLine("777-7777")
        sw.WriteLine("Smith, John")
        sw.WriteLine("888-8888")
        sw.Close()
        Dim numRecords As Integer
        numRecords = NumberOfRecords("MEMBERPHONES.TXT")
        Dim sr As IO.StreamReader …
CodeDoctor 0 Light Poster

hi

i developed an app in VS 2008 with vb.net which was intended to have reporting features but unfortunately deploying with crystal reports was too hard so i chose to go with .rdlc but i'm completely clueless on how to use it, whether it has a report viewer, how it accesses information from my db, etc ....

thanx

This is a good approach, the idea behind creating embedded reports using SQL Reporting is as follows.

The RDLC file is the report, then you need to use the ReportViewer control on a form to initialize the report.

A good example can be found here : http://msdn.microsoft.com/en-us/library/aa337089.aspx

Hope this helps.

CodeDoctor 0 Light Poster

I m creating an sms based application , so how to connect to GSM MODEM using VB.net , do any one have code snippet of this appl

If you are creating a full fledged SMS app, I will consider you look at using the Windows Mobile API's.

They have an Emulator that you can use directly in Visual Studio to create these applications, there are also How-To Videos and Webcasts available to you for creating text messaging interfaces for this platform.

You can start here : http://msdn.microsoft.com/en-us/windowsmobile/default.aspx

Hope this helps.

CodeDoctor 0 Light Poster

Hello Friends,

When i try to show VB.net interop forms within VB 6.0 i have got the error "object variable or with block variable not set ". I was create interop form library in vb.net and use the created TLB as a referece in VB 6.0 and in button click i write the following code.

Dim frm As TestInterop.InteropForm1
frm.Show

when i run the vb project and click on the button i got the above error.
Can you please provide a solution for this. Please reply me as early as possible.

Regards,
Vasanth.

You will need to Instantiate the form before you use it.

Dim frm As [B]New[/B] TestInterop.InteropForm1
frm.Show
CodeDoctor 0 Light Poster

Hello To All,


I want to implement peer-to-peer video streaming in my WPF project.
Plz help me by referring any web site or sample code which i can use
in my project.
Thanks in Advance


With Best Regards
Hardeep Singh Bhullar
er.hardeepbhullar@gmail.com

This is a rather complex issue. Assuming what type of effort you are willing to put into this, there are many options you can research to accomplish this.

If you visit http://msdn.microsoft.com and search for these topics, all of the API's (Application Programming Interfaces) are available to you free of charge.

Some techniques will use DirectX api to access the underlying Video sub-systems of windows. There are many examples available for download.

Keep in mind that if you are looking to do peer-to-peer streaming, then you may also need to research TCP/IP Sockets and create your own technique for getting video from one system to the other.

CodeDoctor 0 Light Poster

hmm could be even easier.
if you have functions that you need to call from different forms you can do two things:
hand over the control you want to write, edit or w/e
in example

Friend sub setLabelText (byval lbl as Label)
'do some calculations here
lbl.text=calculation
End Sub

'in your form you then call
setLabelText (Label1)

or you create functions that returns values

Friend Function setLabelText () As string
'do some calculations here
return calculation
End Function

'in your form you then call
Label1.Text=setLabelText

on this way you dont need this confusing Form1.textbox1.text stuff
Another thing....the functions can be declared as Friend (which means known inside your application)

In reading this post, I noticed that one of the main things being overlooked is the use of objects.

Objects (classes) are 'self contained' units of work, and is used throughout the .NET framework.

If the code used in your form is becoming long and unmanagable, I will suggest you begin looking at your UI (User Interface) differently than you may have in the past.

A good way of doing this, is simply seperate out each of the pieces of the user interface, and instead of drawing controls on the form, create and use User Controls. A user control can easily be created in a seperate file and one or more individual form controls can be placed within it.

As you design this control, understand it will be placed on the form, so to get …

CodeDoctor 0 Light Poster

What is the difference between Common Language Interface and Common Language Infrastructure? Please explain.

Not sure which context you are asking about, however, I will try and answer what I think you are asking.

Common Language Interface (as it applies to .NET) is used by Programming Languages to implement their languages for use in .NET

Common Language Infrastructure (as it applies to .NET) encompasses .NET and the Visual Studio .NET IDE and is used to implement the Common Language Interface within the Visual Studio environment.

Hopefully this helps.

CodeDoctor 0 Light Poster

You can build crystal reports right in the visual studio software too without the need of purchasing any full seperate editions of crystal reports.

It has been 4 years or so since using Crystal, so they may have relaxed the licensing model. However, I do recall needing development licensing in place prior to developing anything that uses the Crystal Reports in a production app.

CodeDoctor 0 Light Poster

Hi Experts,

At the office, we are trying to decide if we want to go with Crystal Reports or ComponentOne. If anybody has used both could you list some advantages and disadvantages?

Thanks!

I've used both, pending on how much control you need both work quite well.

Crystal has alot more options in regards to what types of datasources you can use. But keep in mind, they are licensing costs associated to Crystal. ComponentOne may have, but I don't recall.

Another 'Free' option is using the built in SQL Reports inside of Visual Studio. Assuming you are using SQL Server for your database you can create reports directly inside of your project and embed them free of charge. Another nice thing is that they can bind to either datasets or business objects directly in your code.

You can either deliver these reports in a Windows Form app or an ASP.NET app. Very flexible and powerful capabilities.

CodeDoctor 0 Light Poster

I have two function that replace certain strings in a text file. The first one works perfectly:

Dim readAlias As String
        Dim RxDIR As String = Nothing
        Try
            RxDIR = Registry.GetValue("HKEY_LOCAL_MACHINE\Software\RLtd\R", "MAIN", False)
            RxDIR = RxDIR + "\Bin\Configuration\alias.config"

            Dim sr As StreamReader = File.OpenText(RxDIR)

            readAlias = (sr.ReadToEnd())

            sr.Close()
            sr.Dispose()

            Dim aliasResults As String = readAlias.ToString

            Dim aliasMainDB As String = "database=""(?<name>.+)"""

            Dim m As Match = Regex.Match(readAlias, aliasMainDB, RegexOptions.IgnoreCase Or RegexOptions.Multiline)
            If (m.Success) Then
                'MessageBox.Show(m.Groups("name").Value)
                Dim replace As String = m.Groups("name").Value

                readAlias = Regex.Replace(readAlias, replace, cbListDB.SelectedItem, RegexOptions.IgnoreCase)

                Dim sw As StreamWriter = New StreamWriter(RxDIR)
                sw.Write(readAlias)

                sw.Close()
                sw.Dispose()

                Call mainConfig()

            End If

        Catch ex As Exception

        End Try

The second one runs without error but does not make any changes:

Dim readAlias As String
        Dim RxDIR As String = Nothing
        Try

            workingSQLconnection = "Data Source= " + NameSQL + " ;Initial Catalog=Master;User ID=**;Password=**"

            RxDIR = Registry.GetValue("HKEY_LOCAL_MACHINE\Software\RLtd\R", "MAIN", False)
            RxDIR = RxDIR + "\Bin\Configuration\Templates\alias.config"

            Dim sr As StreamReader = File.OpenText(RxDIR)

            readAlias = (sr.ReadToEnd())

            sr.Close()
            sr.Dispose()

            Dim aliasResults As String = readAlias.ToString

            Dim aliasServer As String = "server=""(?<name>.+)"""

            Dim m As Match = Regex.Match(readAlias, aliasServer, RegexOptions.IgnoreCase Or RegexOptions.Multiline)

            If (m.Success) Then

                Dim replace As String = m.Groups("name").Value

                readAlias = Regex.Replace(aliasResults, replace, NameSQL, RegexOptions.IgnoreCase)

                Dim sd As StreamWriter = New StreamWriter(RxDIR)
                sd.Write(readAlias)

                sd.Close()
                sd.Dispose()

            End If

            Return True

        Catch ex As Exception
            MessageBox.Show(ex.Message)

            Return False

        End Try

The first one is setting a SQL database name ie: mainDB or backupDB.

The second sub is setting the SQL server instance ie: MYPC\SQLEXPRESS

Both are within private functions …

CodeDoctor 0 Light Poster

I dont know what im doing wrong, but the dataadapter, doesnt
find the table im looking for:

Public Shared Function DSet(ByVal ID As Integer, ByVal Name As String, ByVal Address As String, ByVal City As String, ByVal State As String, _
ByVal ZipCode As Integer, ByVal Phone As String) As DataSet
Dim daAdapter As SqlDataAdapter
Dim scConnection As SqlConnection = Nothing
Dim ds As DataSet = Nothing
Try
Dim rCommand As String
rCommand = "INSERT INTO WholeSaler_Details VALUES (" & ID & ", " & Name & ", " & Address & ", " & _
City & ", " & State & ", " & ZipCode & ", " & Phone & ")"
scConnection = GetConnection()
daAdapter = New SqlDataAdapter
ds = New DataSet
daAdapter.InsertCommand = New SqlCommand(rCommand, scConnection)
daAdapter.Update(ds, "WholeSaler_Details")
scConnection.Close()
Return ds

Catch sqlEx As SqlException
MessageBox.Show(sqlEx.Message, _
"Error Encontrado", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return ds
Finally
scConnection.Close()

End Try
End Function

Another thing to keep in mind, above where you are creating the rCommand string, you need to supply literals on text and date fields. ex.

rCommand = "INSERT INTO WholeSaler_Details VALUES ('" & ID & "', '" & Name & "', '" & Address & "', '" & _
            City & "', '" & State & "', '" & ZipCode & "', '" & Phone & "')"

Notice the single quote character before each …

CodeDoctor 0 Light Poster

Hi,


I am trying to get the html source of the particular webpage that having different frames.i want the html source of a particular frame.

Thank you in advance

Working with the WebBrowser control you can access the Frames within any document.

WebBrowser1.document.window.frames("FrameName").document.body.innerHTML

If yo don't have the name of the frame, simply traverse through the each of the HTMLElement objects checking for the TagName="FRAME" to obtain it's name.

Hope this helps.