Home | Index | Dotnet4all Snippets | Submit resources
About | Mail us 





How to add Progressbar to listview (Thursday, November 25, 2004)

Found the following interesting discussion in the Newsgroups:

Progressbar in listview...
by:George L.

Hello, is it possible to add a progress bar as a subitem in a listview? I
want to present the progress of a download similar to a p2p program. Any
other suggestion? I tried with GDI+ but with no success. Thanx...


 Reply:
by:Ray Cassick \(Home\)

 Try this...

http://www.codeproject.com/cs/miscctrl/aa_listview.asp



Posted by Xander Zelders
0 Comments



Binary file I/O using methods of streamreader and streamwriter

Found the following interesting discussion in the Newsgroups:

Binary file I/O using methods of streamreader and streamwriter
by:pdbuchan@yahoo.com (David Buchan)

Hello,

I wonder if anyone could help me.

I'm using vb.NET and I'd like to read a binary file, byte by byte, and
then write to another file (making a duplicate, identical file).

I'd then like to modify the program to take the integer value of each
byte and say, add or subtract an integer from it, with the result
still being an integer from 0 to 255. Then write another file that is
just a list of the integers (as a column of numbers).

I think that vb6 allowed the use of GET and PUT, but I don't think
vb.NET allows those anymore. I believe I have to use the methods of
streamReader and streamWriter to accomplish the task, but I don't know
how.

Thanks,
Dave


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
> I think that vb6 allowed the use of GET and PUT, but I don't think
> vb.NET allows those anymore. I believe I have to use the methods of

In VB.NET, they are called 'FileGet' and 'FilePut'.

> streamReader and streamWriter to accomplish the task, but I don't know
> how.

Alreadly had a look at the 'Read', 'ReadLine', 'Write', 'WriteLine'
methods and their overloaded versions?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


 Reply:
by:Jay B. Harlow [MVP - Outlook]

 David,
If you are operating strictly byte reads & writes all you need is Stream or
FileStream.

I would use something like:

Dim inputPath As String
Dim outputPath As String

Dim input As New FileStream(inputPath, FileMode.Open,
FileAccess.Read)
Dim output As New FileStream(outputPath, FileMode.Create,
FileAccess.Write)

Dim count As Integer = 1024
Dim buffer(count - 1) As Byte

count = input.Read(buffer, 0, count)
Do Until count = 0
' modify each byte in buffer here
output.Write(buffer, 0, count)
count = input.Read(buffer, 0, count)
Loop

input.Close()
output.Close()

StreamReader & StreamWriter are more useful when you want to translate a
text stream to/from "primitive" values, such as Integer, Double, and String.

BinaryReader & BinaryWriter are useful when you want to translate a binary
stream to/from "primitive" values, such as Integer, Double, and String.

Hope this helps
Jay


 Reply:
by:George L.

 
If you want to copy a file you can use "File" class from System.IO
E.x) File.Copy("SourceFileName", "DestFileName")

Now, if you want to work with the bytes of a file you can use "FileStream"
class
from the same namespace.

Dim FS as new Filestream("FileName",Mode)
Dim Buffer() as byte

'Get the bytes from file to a byte array
redim Buffer(FS.Length-1)
FS.Read(Buffer,0,Buffer.Length)

'Do your stuff... :-)
For i as int32=0 to Buffer.Length-1
Buffer(i) = '...... Your code.
next

'Save the byte array and close the stream.
FS.Position=0
FS.Write(Buffer,0,Buffer.length)
FS.Close

I hope this works for you...
George


 Reply:
by:pdbuchan@yahoo.com (David Buchan)

 Thanks guys.

FileStream looks like just the ticket.

I appreciate all the responses.

Dave



Posted by Xander Zelders
0 Comments



How to handle Events in a User Control

Found the following interesting discussion in the Newsgroups:

Event in a User Control
by:Paul Bromley

Can someone give me a very simple example on how to do this? As an example I
have a commaned button in a user control. Once this user control is placed
on a form I want to be able to respond in the form to the button click on
the user control. In a simple example - how do I do this. Do I need to use
Delegates, and if so can you give a very simple example.

Many thanks

Paul Bromley


 Reply:
by:Paul Bromley

 I forgot to ad to this, that when I click the button on my usercontrol, I
would like to call a subroutine in my project and send to it 2 string
parameters. I have invested a lot of time on user controls and delegates and
am about to give up!

Best wishes

Paul Bromley


 Reply:
by:Andy Gaskell

 If you'd like to send some extra information in your events (your 2 strings)
you'll have to create a new class that inherits from the EventArgs class.
Please check out this MSDN link, if you have problems implementing it let me
know.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemeventargsclasstopic.asp
Here's a very basic control that raises an event.

Namespace SimpleControlExample

Public Class SimpleControl
Inherits System.Windows.Forms.UserControl

Public Event ButtonClick(ByVal sender As System.Object,
ByVal e As System.EventArgs)

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(40, 68)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(76, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Raise Event!"
'
'SimpleControl
'
Me.Controls.Add(Me.Button1)
Me.Name = "SimpleControl"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
RaiseEvent ButtonClick(Me, e)
End Sub
End Class
End Namespace



 Reply:
by:Paul Bromley

 Thanks Andy,

I have now managed to raise an event in my project - just need to sort out
how to get this to call my subroutine and send the strings. One thing that I
had not dones is to create a Namespace for my control and then use an
Imports Statement in my project. I had better get off to bed now! If anyone
else can help then I'd be very grateful. Perhaps I will sort things
tomorrow.

Best wishes

Paul Bromley



Posted by Xander Zelders
0 Comments



Form within a Form

Found the following interesting discussion in the Newsgroups:

Form within a Form
by:Stephen Martinelli

Greetings all

I have a form i want to use as a backdrop for three other forms. I want the
three other forms to be placed at a specific location on the backdrop form.
Im at a loss here....

Steve


 Reply:
by:William Ryan eMVP

 Is doing it as a MDI container applicable here? If not, you can still
create the three instances of the forms, add each one to the first form's
Controls collection and set their position to match what you need.

HTH,

Bill


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
Maybe an MDI environment is what you are looking for. Set the main
form's 'IsMdiContainer' to 'True', and the childrens' 'MdiParent'
property to the container form before showing them.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>



Posted by Xander Zelders
0 Comments



MD5 for Large Files

Found the following interesting discussion in the Newsgroups:

MD5 for Large Files
by:Richard Lemay

I am new to VB.NET and I am trying to learn. So, your indulgence for the
triviality of my questions is kindly requested.

I would like to calculate an MD5 hash for very lage files. The examples I
came across read the file into a byte array and apply the hash to that
array. The following code illustrates what I am doing. I would like to
perform the hash calculation on a stream. Is this possible? If so, an
example would be greatly appreciated.

Imports System.Text
Imports System.Security.Cryptography
Imports System.IO

Public Class Form1
Inherits System.Windows.Forms.Form
Dim fs As FileStream = New FileStream("c:\ConfDenise.PDF",
FileMode.Open)
Dim r As BinaryReader = New BinaryReader(fs)

Public Function GenerateHash(ByRef Buff() As Byte) As String
Dim Md5 As New MD5CryptoServiceProvider()
Dim ByteHash() As Byte = Md5.ComputeHash(Buff)
Return Convert.ToBase64String(ByteHash)
End Function

#Region " Windows Form Designer generated code "
' snip
#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
fs.Seek(0, SeekOrigin.Begin)
Label1.Text = GenerateHash(r.ReadBytes(fs.Length))
End Sub
End Class

--
Richard
Please reply to group or
Remove 'REMOVE' from my email address.


 Reply:
by:Rob Teixeira [MVP]

 If you are familiar with Block cipher encryption in .NET, hashes are
supposed to work the same way.
In other words, hash algorithms (like MD5) implement the ICryptoTransform
interface, which allows them to be used by the CryptoStream object.
You could create a memory stream, and wrap it with a CryptoStream, and pass
the MD5 instance to the CryptoStream constructor. Anytime you "write" to the
CryptoStream, it should transform the data through the protecte HashCore
function of MD5. Then, when you are done, you call FlushFinalBlock on the
CryptoStream, which in turn calls the MD5 HashFinal method. Then you can
check the Hash property of the md5 object for the final hash value.

Function GetHash() As String

Dim cs As CryptoStream
Dim ms As MemoryStream = New MemoryStream
Dim md5Hash As MD5CryptoServiceProvider = New MD5CryptoServiceProvider

Try

Dim buffer As Byte() = New Byte() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15}

cs = New CryptoStream(ms, md5Hash, CryptoStreamMode.Write)
cs.Write(buffer, 0, buffer.Length)

cs.FlushFinalBlock()
Return Convert.ToBase64String(md5Hash.Hash())

Catch ex As Exception

MsgBox("Error during hash operation: " + ex.ToString())

Finally
If Not (cs Is Nothing) Then cs.Close()
If Not (md5Hash Is Nothing) Then md5Hash.Clear()
End Try
End Function

The only thing to note is that in my sample, i just filled the buffer once
with a bunch of numbers.
In your case, you need to wrap a Loop around the cs.Write(...) line, and
read from your file to the buffer one chunk at a time, and write the buffer
to the CryptoStream until you run out of file.

-Rob Teixeira [MVP]


 Reply:
by:Richard Lemay

 Thanks Rob,
I'll give it a try.
Richard



Posted by Xander Zelders
1 Comments



How to turn on Caps lock

Found the following interesting discussion in the Newsgroups:

How Caplocks -automically ?
by:Agnes

How can I set "As the form load" , the caplock is on automically ?
I know that I can default the Me.textbox.CharacterCasing =
CharacterCasing.Upper
However, once i set it, the user never can change it .

So I would like to default it is upper case but let the user change it.

Thanks
From Agnes


 Reply:
by:Scott

 Take a look at the examples in this article...

http://www.codeguru.com/vb/gen/vb_system/keyboard/article.php/c4835



Posted by Xander Zelders
0 Comments



How to Set Control colors (Wednesday, November 24, 2004)

Found the following interesting discussion in the Newsgroups:

Setting Control colors
by:Cliff Lane

I have an application that allows the user to select fore and back ground
colors for command buttons. I use the dialog to select the colors and store
the value returned in the db as a string. For standard colors the db values
are "white" etc. For custom colors the values are "ff808040" etc.

When I try to load these values from the db and set the controls colors I am
getting an error. The statement is
control.forecolor = db.fields("forecolor").value
the error returned is
Specified cast is not Valid.

I have tried using ctype but it then tells me the cast is not allowed.

Am I storing the selected value in the db using the correct type?
How can I set these values

Cliff


 Reply:
by:Ken Tucker [MVP]

 Hi,

Dim clr As Color =
System.Drawing.ColorTranslator.FromHtml("#FF808040")
Button1.BackColor = clr

Ken


 Reply:
by:sterling@fiac.net

  Dim SomeColor As System.Drawing.ColorTranslator
Dim myColor = SomeColor.FromHtml(db.fields("forecolor").ToString)
myControl.BackColor = myColor



Posted by Xander Zelders
0 Comments



Option Strict On Question

Found the following interesting discussion in the Newsgroups:

Option Strict On Question
by:Timmy

VB.Net Standard 2003, Win2k Pro

The following code generates the late binding msg "Option Strict On
disallows late binding". How do I correct this and still have Strict On?

Thanks,

GG

Option Strict On
~
~ code
~
Private Sub AxWebBrowser1_DownloadComplete(ByVal sender As Object, ByVal e
As System.EventArgs) Handles AxWebBrowser1.DownloadComplete

'rtbHTML is a richtextbox on a form
rtbHTML.Text = AxWebBrowser1.Document.documentElement.innerhtml

End Sub


 Reply:
by:Ken Tucker [MVP]

 Hi,

Add a reference to Microsoft HTML object library in the com tab.

Private Sub AxWebBrowser1_DownloadComplete(ByVal sender As Object, ByVal e
As System.EventArgs) Handles AxWebBrowser1.DownloadComplete
Dim doc As mshtml.HTMLDocumentClass

doc = CType(AxWebBrowser1.Document, mshtml.HTMLDocumentClass)

RichTextBox1.Text = doc.documentElement.innerHTML
End Sub

Ken
------------------


 Reply:
by:Gordon

 Excellent. Thank you very much Ken.

GG



Posted by Xander Zelders
0 Comments



Crystal Decisions problem

Found the following interesting discussion in the Newsgroups:

Crystal Decisions problem
by:Rich

Hi,

I've created an application in VS 2002 using vb.net. My application contain
a Crystal Decisions report and when I run it on my development PC with VS
installed it works fine. However, when I install it on the users PC I get
this error :

System.IO.FileNotFoundException: File or assembly name
CrystalDecisions.Windows.Forms was not found.

I thought that you could redistribute apps with Crystal Reports in them and
they would work without the user have to have a copy of Crystal Reports
installed? Can anyone tell me if this is correct, and if it is what I need
to do to get it to work - is there an update or patch to install?

Many Thanks
Richard


 Reply:
by:Bernie Yaeger

 Hi Rich,

Yes, you can redistribute any CR report, and you don't have to install a
version of CR on each pc. However, you have to install the various merge
modules that CR makes freely available so that the reports can run properly
on each target machine.

Go to businessobjects.com and look up 'merge module' or '.net install' to
get the instructions necessary - it's not too difficult.

HTH,

Bernie Yaeger


 Reply:
by:Merlin

 Hi,

Yes you can redistrubute apps with Crystal reports and the end user does not
need Crystal Installed. I personally use Merge Modules from the Crysal
site - check out the link below which takes you to the support pages, from
here you should be able to search for the merge modules - it's then a simple
case of adding them to your installation project.

The files I always include with my projects are:-
crnetruntime.msm
mapping.msm
reportengine.msm

http://www.businessobjects.com/services/support/default.asp

Regards



Posted by Xander Zelders
0 Comments



Sub Classes

Found the following interesting discussion in the Newsgroups:

Sub Classes
by:Anonymous

What is the benefits of having a class within a class?

Thanks in advance for the info.


 Reply:
by:CT

 I'm not sure these are benfits, but more why and how you should use nested
classes:

1) It's accesible only through the containing class.
2) If the class is only meaningful to one other class, why not nest it
within this other class, thus indicating to other developers the exact use
of the class.

--
Carsten Thomsen


 Reply:
by:Rob Teixeira [MVP]

 It's a matter of encapsulation. It allows you to create private utility
classes that are only visible to the containing class.

One more note, though -
I've seen a few people call these sub-classes or subclasses, but the real
name is "nested class". Subclasses are classes that inherit from another
base class (or superclass).

-Rob Teixeira [MVP]


 Reply:
by:Chris Dunaway

 
I prefer the term "derived class", but I guess I get that from C++, but I
know they mean the same thing.

Cheers

--
Chris



Posted by Xander Zelders
0 Comments



Class within a Class?

Found the following interesting discussion in the Newsgroups:

Class with In a Class?
by:jose_mendez22@hotmail.com (JoseM)

In vb.net what is the benefit of having a class within a class?

If anyone can pass the knowledge it would greatly be appreciated.


 Reply:
by:Andy Holliman

 It's a very broad question but possible reasons include:
A property of a class being another class
Using inherits to extend behaviour - eg create a base class 'Individual'
that handles Name and Addess functionality

This can then be inherited to a customer class, a contact, a patient etc

Have alook at the topic Visual Basic Language Concepts - Inheritance in
MSDN for more


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
In addition to the other reply: Have a look at the .NET framework class
library to see in which situations nested classes make sense.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


 Reply:
by:Jay B. Harlow [MVP - Outlook]

 JoseM,
As the others suggest, can you be a little more specific in what you are
asking?
Do you mean a nested class?

Public Class Class1
Private Class Class2
End Class
End Class

Having Class2 nested inside of Class1 is a form of Encapsulation, I would
use this when Class2 is an implementation detail of Class1 and Class2 is not
needed anyplace else, such as the Node class of a LinkedList class, where
the Node represents the "links" in the LinkedList.

Something like (greatly simplified):

Public Class LinkedList

Private Class Node
Public Data As Object
Public Next As Node
Public Previous As Node
End Class

Private m_head As Node
Private m_tail As Node

Public Sub Add(data As Object)
Dim node As New Node
node.Data = data
node.Next = m_head
node.Previous = Nothing
m_head = node
End Sub
End Class

The Node class is nested inside of LinkedList as it is not useful outside of
the context of a LinkedList. Having Node private to LinkedList ensures that
only LinkedList is able to use the Node class.

Hope this helps
Jay



Posted by Xander Zelders
0 Comments



ComboBox resize changes the text

Found the following interesting discussion in the Newsgroups:

ComboBox resize changes the text
by:Mark P

How to solve this?

1. Place a ComboBox in a form

2. On the ComboBox Properties window change the Items to hold:

a
b
c
d

3. On the ComboBox Properties window change the Text to A

4. Resize the ComboBox and notice that the display Text changed from 'A'
to 'a'

5. On the ComboBox Properties window change the Text to P

6. Resize the ComboBox and notice that the display Text still is 'P'



 Reply:
by:CT

 I don't see the signficance of this; if the value you enter in the Text
property exists on the Items list, the casing is chnaged when you resize.
Try C or D, and the same will happen as with the A. Not with P as it doesn't
exist on the list.

--
Carsten Thomsen


 Reply:
by:Mark P

 once more I ask the kids to go to playground or read answers instead of
being 'highlighted'


 Reply:
by:CT

 Feel free to interpret the answer any way you like; it won't change
anything...




Posted by Xander Zelders
0 Comments



ComboBox resize changes the text

Found the following interesting discussion in the Newsgroups:

ComboBox resize changes the text
by:Mark P

How to solve this?

1. Place a ComboBox in a form

2. On the ComboBox Properties window change the Items to hold:

a
b
c
d

3. On the ComboBox Properties window change the Text to A

4. Resize the ComboBox and notice that the display Text changed from 'A'
to 'a'

5. On the ComboBox Properties window change the Text to P

6. Resize the ComboBox and notice that the display Text still is 'P'



 Reply:
by:CT

 I don't see the signficance of this; if the value you enter in the Text
property exists on the Items list, the casing is chnaged when you resize.
Try C or D, and the same will happen as with the A. Not with P as it doesn't
exist on the list.

--
Carsten Thomsen


 Reply:
by:Mark P

 once more I ask the kids to go to playground or read answers instead of
being 'highlighted'


 Reply:
by:CT

 Feel free to interpret the answer any way you like; it won't change
anything...




Posted by Xander Zelders
0 Comments



How to Insert A New Record

Found the following interesting discussion in the Newsgroups:

Inserting A New Record
by:Curt Emich

Can someone tell me specifically what's missing in this code so that it
won't write the record into the database? Please, no references to lengthy,
bloated, meandering articles telling me how to make a watch when I'm merely
asking what time it is.

Dim thisDataAdapter As OleDb.OleDbDataAdapter = New
OleDb.OleDbDataAdapter("SELECT * FROM Sessions", OleDbConnection1)

thisDataAdapter.InsertCommand = New OleDb.OleDbCommand("INSERT INTO Sessions
SET Notes = ? ", OleDbConnection1)

thisDataAdapter.InsertCommand.Parameters.Add("Notes", OleDbType.VarChar, 15,
"Notes")

' Dim workParm As OleDbParameter =
catDA.UpdateCommand.Parameters.Add("@CategoryID", OleDbType.Integer)

' workParm.SourceColumn = "CategoryID"

' workParm.SourceVersion = DataRowVersion.Original

Dim thisDataset As DataSet = New DataSet()

thisDataAdapter.Fill(thisDataset, "Sessions")

Dim thisTable As New DataTable()

thisTable = thisDataset.Tables("Sessions")

Dim cRow As DataRow = thisTable.NewRow()

cRow("Notes") = "Yadda"

thisTable.Rows.Add(cRow)

thisDataAdapter.Update(thisDataset)



 Reply:
by:Bernie Yaeger

  Curt,

The logic of the table assignment is backwards. You're trying to update the
permanent table 'sessions' but you're actually updating the temporary table
'thistable'.

Do this instead:
crow = thisdataset.Tables(0).NewRow()

etc.

HTH,

Bernie Yaeger


 Reply:
by:Curt Emich

 

Thanks. Yeah, I caught that a while ago, but still nothing. I went to
this link

http://www.dotnetextreme.com/code/BasicAdo.asp

and copied the code verbatim and still don't get a new record. I'm
starting to wonder about my connection.


 Reply:
by:Bernie Yaeger

 Hi Curt,

Try, for starters, using a simple commandbuilder, as in this very direct and
simple code snippet:
Dim davwbillex As New SqlDataAdapter("select * from vwbillex", oconn)

Dim dsvwbillex As New DataSet("vwbillex")

davwbillex.Fill(dsvwbillex, "vwbillex")

Dim commandbuilder_vwbillex As SqlCommandBuilder = New
SqlCommandBuilder(davwbillex)

mrow = dsvwbillex.Tables(0).NewRow()

mrow("retcode") = "54901"

mrow("inv_dt") = Date.Now.Date

dsvwbillex.Tables("vwbillex").Rows.Add(mrow)

Try

davwbillex.Update(dsvwbillex, "vwbillex")

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

If this works ok (you'll need, of course, a table with this structure), then
there's nothing wrong with the connection.

Let me know.

Regards,

Bernie



Posted by Xander Zelders
0 Comments



How to return array of objects

Found the following interesting discussion in the Newsgroups:

How to return array of object
by:Anonymous

hi i need to send some data to the function and want to return array of object back
like

dim obj() as myclass=AddIt(i,j)
i dont know that is write syntax or not

public function addit(byval i as interger, byval j as integer) as myclass
dim obj(20) as myclass
obj(0).additem( i,j)
obj(1).additem(i,j)
..
..
obj(20).additem(i,j)
return obj
end function
if some body give me help how to do that


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 * =?Utf-8?B?QWxp?= <anonymous@discussions.microsoft.com> scripsit:
> hi i need to send some data to the function and want to return array of object back
> like
>
> dim obj() as myclass=AddIt(i,j)
> i dont know that is write syntax or not
>
> public function addit(byval i as interger, byval j as integer) as
> myclass

'... As MyClass()'.

> dim obj(20) as myclass
> obj(0).additem( i,j)
> obj(1).additem(i,j)
> .
> .
> obj(20).additem(i,j)

'obj(i) = ...'.

> return obj
> end function
> if some body give me help how to do that

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


 Reply:
by:Poolbeer \(MCP\)

 You should add parenthesis to the return object...
Syntax sample below

Your implmentation of AddIt
public function addit(byval i as interger, byval j as integer) as myclass

Corrected AddIt
Public Function AddIt(ByVal i As Integer, ByVal j As Integer) as myClass()

Hope it helps
--

Poolbeer (MCP)



Posted by Xander Zelders
0 Comments



How to create collection object with vb.net

Found the following interesting discussion in the Newsgroups:

How to create collection object with vb.net
by:Anonymous

hi i know to create collection of object with vb
but dont know how to do that thing using vb.net
thanks


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 

\\Dim c As New Collection() ' or ArrayList.
c.Add(...)
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


 Reply:
by:Anonymous

 sorry it was not
let me explain a bit

i have a class suppose student and i want to store different information about student and want to create student collection so if i add student i have to just call add function and also i dont have to specify the length of array



 Reply:
by:Chris Dunaway

 On Sat, 8 May 2004 11:06:01 -0700, khan wrote:

> i have a class suppose student and i want to store different information about student and want to create student collection so if i add student i have to just call add function and also i dont have to specify the length of array

You can use an ArrayList for this.

Dim alStudents As New ArrayList

Dim oStudent As New StudentClass

alStudents.Add(oStudent)

--
Chris



Posted by Xander Zelders
0 Comments



How to find the host from an ip adress

Found the following interesting discussion in the Newsgroups:

DNS problem
by:Anonymous

Hi

I have a list of ip addresses that i need to return the host name's from a dns server , i can find loads of code for host name lookup which returns an ip address , but none for an ip lookup.

Does anybody have any ideas

Regards
Neil


 Reply:
by:Rob Teixeira [MVP]

 System.Net.DNS.GetHostByAddress

-Rob Teixeira [MVP]



Posted by Xander Zelders
1 Comments



(how to) International Number Formatting

Found the following interesting discussion in the Newsgroups:

International Number Formatting
by:Steve Peterson

Hi

I have an app where I have to deal with both Spanish & American formatting.
I have a string that represents a number that I need to convert to Int32
before I enter it in the database. The string can be any number, for
example, "1,355" (American style) or "1.355" (Spanish style) . I know could
use the Replace method and "strip" the number string of "." or the "," then
convert what is left to Int32.

But I thought maybe there is a better way using the CultureInfo class that
simply converts any culture number sting to a number. However, I'm having
problems figuring this one out.

Can anyone lend a helping hand?

TIA

Steve


 Reply:
by:Ken Tucker [MVP]

 Hi,

Dim strEng As String = "1,355"
Dim strSpanish As String = "1.355"

Dim intEng As Integer = Integer.Parse(strEng,
Globalization.NumberStyles.AllowThousands, New
System.Globalization.CultureInfo("en-US"))

Dim intSpanish As Integer = Integer.Parse(strSpanish,
Globalization.NumberStyles.AllowThousands, New
System.Globalization.CultureInfo("es-ES"))

Trace.WriteLine(String.Format("{0} = {1}", strEng, intEng))
Trace.WriteLine(String.Format("{0} = {1}", strSpanish, intSpanish))
Ken


 Reply:
by:Steve Peterson

 Thanks Ken

That did the trick!

Steve



Posted by Xander Zelders
0 Comments



how to initialize array of object with vb.net

Found the following interesting discussion in the Newsgroups:

how to initialize array of object with vb.net
by:Anonymous

I am doing vb.net programming
my problem is
dim myobject() as myclass
i am craeating dynamic array of my object and later i am specifing length of array like
set myobject=new myclass()
redim myobject(TotalLength)
i dont know is that correct sentence i am using cos i am new to vb.net
thanks


 Reply:
by:Armin Zingler

 
I'm not sure what you need.

Use
Redim myobject(upperbound)
to create a new array. Use Redim Preserve to keep the content.

Use
Myobject(index) = new yourclass
to create an new instance of your class and store the reference in the
array.
--
Armin


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
'ReDim Preserve MyObject(TotalLenght - 1)'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>



Posted by Xander Zelders
0 Comments



How to Connect to mysql

Found the following interesting discussion in the Newsgroups:

Connecting to mysql
by:dennis.claes@skynet-dot-be.no-spam.invalid (s5034454)

Hello, I'm trying to connect to a mysql database. I have already
taken these steps:
1) downloaded and installed odbc_net.msi
2) downloaded and installed mdac_typ.exe (mdac 2.7 or something)
3) written this code:

Imports System.Data.Odbc.OdbcConnection

Public Class Test
Inherits System.Windows.Forms.Form

+ windows form designer generated code

Private Sub Test_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim MyConString As String = "DRIVER={MySQL ODBC 3.51
Driver};" & _
"SERVER=db.pcextreme.nl;" & _
"DATABASE=test;" & _
"UID=root;" & _
"PASSWORD=pass;" & _
"OPTION=3"
Dim MyConnection As New
System.Data.Odbc.OdbcConnection(MyConString)

MyConnection.Open()
End Sub
End Class

But VB.NET doesn't recognize the namespace and I can't find it in the
"add reference" list. Could anyone help me?



 Reply:
by:Ken Tucker [MVP]

 Hi,

Framework version 10 use Imports Microsoft.Data.Odbc

Framework version 1.1 use Imports System.Data.Odbc

Ken


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
<URL:http://www.connectionstrings.com/>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>



Posted by Xander Zelders
0 Comments



How to populate a listbox

Found the following interesting discussion in the Newsgroups:

populate listbox
by:Mike

How can i populate a list box from a text file?

I create a list of files within a text file and I want to populate the list
box with that list to allow the users to select the web server to test
against.

how can i do that?


 Reply:
by:William Ryan eMVP

 use the IO class and a text reader, at each pass where there's a delimmiter
for instance, use Listbox.Items.Add



Posted by Xander Zelders
0 Comments



Decimal To Binary Function Does Not Work (Tuesday, November 23, 2004)

Found the following interesting discussion in the Newsgroups:

Decimal To Binary Function Does Not Work
by:Anonymous

I am using the following sub but i am getting inaccurate output

Public Function Convert(ByVal Base As Integer, ByVal Number As Integer) As String

Do
If Not Number / Base = 0 Then
Convert &= (Number Mod Base).ToString
Number = Number / Base
Else
Return StrReverse(Convert)
End If
Loop

End Function

Does any one know why this is not working?

Thanks for any help in advance


 Reply:
by:Jay B. Harlow [MVP - Outlook]

 WStoreyII,
Do you need to use floating division?

I would expect that Integer division would be better.

Remember "/" is floating division, while "\" is integer division.

Or are you referring to the fact your routine drops the leading digit?
Have you considered using System.Convert.ToString(value as Integer, tobase
As Integer) instead?

Have you tried:

> Public Function Convert(ByVal Base As Integer, ByVal Number As Integer)
As String
>
> Do
> If number <> 0 Then
> Convert &= (Number Mod Base).ToString
> Number = Number \ Base
> Else
> Return StrReverse(Convert)
> End If
> Loop
>
> End Function
>

Note the above returns nothing when the input = 0!

Hope this helps
Jay



Posted by Xander Zelders
0 Comments



How to Run a batch file by passing parameters with in a button click

Found the following interesting discussion in the Newsgroups:

Run a batch file by passing parameters with in a button click
by:sukanya s via .NET 247


i am doing a project in asp.net (web application).Can anyone please tell me how to run a batch file within a button click event,also i need to pass parameters from my application to that batch file.Very urgent.Kindly reply immediately.thanks in advance.


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
Did you have a look at 'System.Diagnostics.Process', its 'Start' method
and 'ProcessStartInfo'?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>



Posted by Xander Zelders
2 Comments



WTSAPI32 Dll entry point missing for WTSSendMessage

Found the following interesting discussion in the Newsgroups:

WTSAPI32 Dll entry point missing for WTSSendMessage
by:Monty via .NET 247

Hi,

I am calling a dll which is wrapper around WTSAPIs from vb.net application. I am trying to use WTSSendMessage api which sends a message to the user based on session id. But I am getting error that DLL entry point not found in WTSAPI32.lib. MSDN says the api is available and I have check the requirements too. My system is WIN2k server with sp4 and citrix metaframe xp1. Any Ideas ??


 Reply:
by:Mattias Sjögren

 
The function is available in ANSI and Unicode versions
(WTSSendMessageA and WTSSendMessageW). Make sure you use the Auto
modifier in your Declare statement.

Declare Auto Function WTSSendMessage ...

Mattias



Posted by Xander Zelders
0 Comments



winmm.dll

Found the following interesting discussion in the Newsgroups:

winmm.dll
by:Anonymous

Hallo
I've seen this file 'winmm.dll' a bit in examples and stuff but I don't know what it is. Can someone please explain what it is
thanx


 Reply:
by:Tom Shelton

 
It's the windows multimedia dll... It contains several routines - such as
precision timing, controlling mutlimedia devices, etc - that are sometimes
usefull.

--
Tom Shelton [MVP]


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
See:

<URL:http://msdn.microsoft.com/library/en-us/multimed/htm/_win32_multimedia_reference.asp>



Posted by Xander Zelders
1 Comments



How to play sounds that don't exist.

Found the following interesting discussion in the Newsgroups:

playing sounds that don't exist.
by:Anonymous

hi
I've found some code for playing sounds and it kinda works. This is what I have.

\\\\\Public Class SoundClass
Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name As String, _
ByVal hmod As Integer, ByVal flags As Integer) As Integer
' name specifies the sound file when the SND_FILENAME flag is set
' hmod specifies an executable file handle
' hmod must be Nothing if the SND_RESOURCE flag is not set
' flags specifies which flags are set
Public Const SND_SYNC = &H0 ' play synchronously
Public Const SND_ASYNC = &H1 ' play asynchronously
Public Const SND_FILENAME = &H20000 ' name is file name
Public Const SND_RESOURCE = &H40004 ' name is resource name or atom
Public Sub PlaySoundFile(ByVal filename As String)
' Plays a sound from filename
PlaySound(filename, Nothing, SND_FILENAME Or SND_ASYNC)
End Sub
End Class

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim SoundInst As New SoundClass
SoundInst.PlaySoundFile("C:\ringout.wav")
End Sub
/////////

Now pressing the button doesn't do anything I just get an error noise.
If I change the
("C:\ringout.wav")
to
("ringout.wav")
it plays a sound of a phone ringing. This weird because I don't have a music file called ringout.wav!
It said to use ("C:\ringout.wav") in the example on SDK but it doesn't work


 Reply:
by:Ken Tucker [MVP]

 Hi,

Actually you probably have ringout.wav in the windows\media
directory. PlaySound will check the current directory, windows directory,
windows system directory than the directories list in the path environment
for the file.

Ken



Posted by Xander Zelders
0 Comments



How to Execute a method in one form from another

Found the following interesting discussion in the Newsgroups:

Executing a method in one form from another
by:Anonymous

I need to exceute a method in a form from another form... Both forms will always be open so I don't have to worry about that... I just need to call the method... Please help... Source please...


 Reply:
by:Anonymous

 Hi Anthony,

There are different sce... where you can implement. For both the solutions you need to have a Public function only.

1. If you those two forms are MDI Child forms, then you can get the instances using MdiChildren property of the mdiform and call the function.
2. If they are not related, what you can do is, have public module and declare objects for both the forms. and assign the form opened to these corresponding object, use these object to invoke the function.

Sadha Sivam S
Malleable Minds Software,
India.
Micorsoft India Community Star.


 Reply:
by:Paul Bromley

 Hi Anthony,

I posted a simialr question to the list just below you. I had found the
following solution in the archives and was asking if this was the correct
way of going about things - it does work for me:-

The answer that I have found is to create a module with a Sub Main in it and
set this as the Startup Object:-

Module Startup
Public myMainForm As Form1
Sub Main()
myMainForm = New Form1
Windows.forms.Application.Run(myMainform)
End Sub
End Module

Best wishes

Paul Bromley



Posted by Xander Zelders
0 Comments



How to inherit an attribute with the class it applied to?

Found the following interesting discussion in the Newsgroups:

Can attribute be inherited with the class it applied to?
by:feng

Hi,

I have a class, say class A, that has <Serializable()>
attribute applied to it. Now if I create a class B that
inherits from A, does B automaticly inherits this
attribute also? or do I have to apply <Serializable()> to
B, if I want B to be serializable?

Thanks

Lifeng


 Reply:
by:AlexS

 feng,

note the difference between comment and compiled code. Current attribute
syntax is some kind of comment. While some comments are processed by
compiler, they are basically not the part of actual code. So, attributes
declared in comments or as part of declaration are not inheritable - at
least now. However, you can easily change that by adding attribute field
(property or internal variable) into base class.
Even if at first glance this is not what you want - because functionality
like adding/removing attributes dynamically is not yet supported afaik (btw
this could be next step in evolution of .Net), you will be able to use
inherited attributes in derived classes.

By the way, what could be the purpose of inheriting attribute(s)? To me it
looks more like self-evolving code paradigm, which is clearly not what you
look for.

However I might be a bit wrong here 'cause looked into attributes couple of
years ago during my Beta time :-()
Anybody knows better?

HTH
Alex


 Reply:
by:Mattias Sjögren

 
Serializeble isn't inherited no. But Serializable is a special,
pseudo-custom attribute.

For regular custom attributes, it depends on the AttributeUsage
attribute on the attribute class (wheter it has Inherited=True set).

Mattias



Posted by Xander Zelders
0 Comments



How to create a setup wizard

Found the following interesting discussion in the Newsgroups:

setup wizard
by:AMC

Can someone point me to an article that outlines how to create a setup
project using the wizard?


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
<URL:http://msdn.microsoft.com/library/en-us/vsintro7/html/vxurfSetupWizard.asp>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>



Posted by Xander Zelders
0 Comments



How to get Raw TCP in VB.net form from IIS

Found the following interesting discussion in the Newsgroups:

Need Raw TCP in VB.net form from IIS
by:Anonymous

Hi,
I ned to have my VB.NET webform called on any tcp send to port 80 on IIS so I can see the message and possibly change it on the response.
Basically I need to let IIS act as the socket server and want to ignore or erase the http in the picture...

Can any one give me some ideas or hints how to capture th message?

Currently in the form I only get the HTTP message if the website is called...not on any TCP message to port 80 on the box.

I didn't want to do ISAPI cause if the socket is secure I think i would see encrypted data...but in THE Webform IIS would decrypt and encrypt behind the scenes for me
Thanks very much,
John


 Reply:
by:Rob Teixeira [MVP]

 Short answer - not gonna happen.

Alternative - use the System.Net namespace to create a VB.NET windows
service app that Listens to the ports you want and communicate using raw TCP
sockets (the TCPListener and TCPClient classes should help you there).

Additional question - What is sending messages to IIS on port 80 that
*aren't* HTTP messages anyway? Something just sounds incredibly wrong about
this in a very fundamental way.

-Rob Teixeira [MVP]



Posted by Xander Zelders
0 Comments



How to minimize all forms in MDI

Found the following interesting discussion in the Newsgroups:

minimize all in MDI
by:Brian Henry

what happened to minimize all for mdi windows? I can easily find tile,
cascade, and arrange icons, but not minimize all windows


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
Loop through the MDI container's 'MdiChildren' and set their
'WindowState' to 'Minimized'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>



Posted by Xander Zelders
0 Comments



How to use HttpWebRequest & Authentication

Found the following interesting discussion in the Newsgroups:

HttpWebRequest & Authentication
by:Greg

I've been reading a lot of other posts and trying a bunch of things but just
cannot get this to work. I'm hoping someone can help.

Here's the situation. I have a test folder which only Administrator has
access to. Inside it has a web page. In IIS (Windows 2003), I have
"Integrated Windows authentication" and "Basic authentication" check marked
for the folder -- nothing else.

I can access the folder with IE6 without being prompted for a username and
password (I'm logged in as Administrator).

When I attempt to download the page with the HttpWebRequest I get the error
"401 Unauthorized". When I specify credentials as: Request.Credentials =
New NetworkCredential("Administrator", "mypass", "mymachinename") I also get
"401 Unauthorized".

If I disable "Integrated Windows authentication" it works, but I need that
enabled for other things. This is where my problem is.

Does anyone have any idea what the problem might be?

BTW: This is a normal app run under the Administrator account.

Thanks



 Reply:
by:MadCrazyNewbie

 Is this on a Active Directory, Shared win NT network?

Is this a stand alone server / Member Server / DC?

More Details would be a good Idea?

MCN


 Reply:
by:Greg

 
Thanks for the reply. It's just a single Windows 2003 system. It's not on
a network and AD is not installed.



Posted by Xander Zelders
1 Comments



Structuring code files for multiple programmers work.

Found the following interesting discussion in the Newsgroups:

Structuring code files for multiple programmers work.
by:Gary Shell

I am trying to figure out the best way to subdivide a project for multiple
programmers. I am embarking on a new development project with one other
person but with an idea in mind that we may need to add a couple more folks
on as we progress.

The user interface is an "outlook style one" with a treeview over a small
navigation pane with a splitter bar and a, for lack of a better term,
content area.

Selections made in the treeview will cause the content area to change
dramatically depending on the item selected in the treeview. This content
area will have anywhere from 3 to 10 tabs on it, again dependent on the item
selected in the tree view. All told there will be 30 to 50 different tabs.
I'd like to somehow encapsulate each one of these tabs such that they could
be checked out of SourceSafe individually.

Lets say I have one particular content area configuration which has 6 tabs.
I'd like to be able to assign tabs 1 through 3 to programmer A and 4 through
6 to programmer B. I don't know how I could check in or out just one tab.
It looks to me like all 6 tabs would have to reside on a single form and
that would preclude two developers from working on the twos sets of tabs as
outlined above. The ideal situation would be to have each tab actually
house a form, and then each of these forms could be individually checked
out. But our preliminary tests seem to show that the only thing a tab
"container" can hold is controls, not an entire form.

Anyone else tried to "team program" an "outlook style" of interface with
tabs in the content area? If so how did you structure the app to allow a
highly granular code file structure.

I just know this is gonna be some silly easy answer to this and I'll slam
the heel of my hand into my forehead, exclaiming "Doh!"

Thanks,
Gary Shell


 Reply:
by:AlexS

 It's easy to say Doh when you know the correct answer. It's not that easy to
come to correct answer.

I am not sure my answer is simple or completely correct. Tab as component is
class, and as such could be developed by one person. Same person could
develop several tabs or all. Depends on complexity. While tabs are not yet
complete - you use dumb classes (constructor / destructor). You check in new
version of class, recompile and go.
Of course it could be done in more complex way - not that much maybe - by
using plugin concept. Especially when you don't know how many tabs you or
user will create.

As about specific components - take a look at TabControl and related
TabPage. Because TabPage is inherited from Panel it can host easily other
panels or whatever controls you want to develop. E.g. in one of my programs
I put whole Outlook style interface onto one TabPage.

And possibly you should take a look at some book on object-oriented design?
Petzold's one is very good at demonstrating simple techniques of sensible
inheritance for windows UI components imo.

HTH
Alex



Posted by Xander Zelders
0 Comments



Computed Columns in dataset always returning NULL

Found the following interesting discussion in the Newsgroups:

Computed Columns in dataset always returning NULL
by:Dave

I am relativly new to visual basic, so this may be a no-
brainer.

I am attempting to use a computed column in a VB dataset
defined as followe:

'
'dcCost
'
Me.dcCost.ColumnName = "Cost"
Me.dcCost.DataType = GetType(System.Decimal)
Me.dcCost.Expression = "UnitPrice * Quantity"
Me.dcCost.ReadOnly = True

(IF this looks familiar, then youve probably taken MOC
2389B and done Lab 4)
So far this column only returns NULL after trying the
following:

Constructed the table and column in the visual editor.
Copied the code from the Solutions folder (cheating)
Loaded and ran the solution from the solutions folder.
Changed the expression to "6 + 3" to eleminate any
references to other columns.
Ran the code on another system with visual studio
installed.

I'm running Visual Studio.net 2003 and .net Framework 1.1.
Has anyone else encountered this or know the magic switch
to throw to enable the computed columns ?

Thanks,
Dave.


 Reply:
by:William Ryan eMVP

 Hi Dave:
Are you sure you have valid values in there? I'm thinking you may have
nulls and any operation on null = null. It doesn't equal anythign not even
Null or itself

This code works like a charm for me ( I created a table with Quantity and
Price as columns:

Dim ds As New DataSet
da2.Fill(ds, "PriceQuantity")
Dim dcTotal As New DataColumn("TotalPrice",
System.Type.GetType("System.Decimal"))
dcTotal.Expression = "Price * Quantity"
dcTotal.ReadOnly = True 'Don't really need this
ds.Tables(0).Columns.Add(dcTotal)
DataGrid1.DataSource = ds.Tables(0)




Posted by Xander Zelders
0 Comments



Free Icons

Found the following interesting discussion in the Newsgroups:

Free Icons
by:David Schwartz

Anyone know any good websites where I can find some free icons to add to my
..NET app?

Thanks!


 Reply:
by:Scott

 http://www.vbaccelerator.com/home/Resources/Graphics_Library/Icons/index.asp


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
<URL:http://www.microsoft.com/permission/copyrgt/cop-img.htm>
-> "Icons"

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>



Posted by Xander Zelders
0 Comments



Printing to a Word document using PrintDocument class

Found the following interesting discussion in the Newsgroups:

Printing to a Word document using PrintDocument class
by:Anonymous

Can anyone shed some light on how to output to a Word document using the PrintDocument class? I need to draw lines and filled boxes as well as place text at a specific point on the line. Can this even be done?

Thanks in advance


 Reply:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
I doubt that this is possible. You can use Word automation to print a
word document (<URL:http://msdn.microsoft.com/office/>).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>



Posted by Xander Zelders
0 Comments



Why can't I draw to to the control's graphics?

Found the following interesting discussion in the Newsgroups:

Why can't I draw to to the control's graphics?
by:Juan Romero

Hey guys,

I am trying to draw a vertical line in a class of mine that inherits from
the RichTextBox control, but for some reason the line won't be drawn.

Here is the code, fairly straight forward:

Dim g As Graphics = Me.CreateGraphics
g.DrawLine(Pens.Black, 100, 1, 100, Me.Height)
g = Nothing

Any ideas?


 Reply:
by:Ken Tucker [MVP]

 Hi,

http://msdn.microsoft.com/msdnmag/issues/04/05/AdvancedBasics/default.aspx

Ken



Posted by Xander Zelders
0 Comments



Where is my app.config file??

Found the following interesting discussion in the Newsgroups:

Where is my app.config file??
by:Adone

I have a winforms app that I compiled and put on my client via .NET setup. I
have a webservice on this app. The External address for this