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

 
Strategy / direction? (Thursday, December 09, 2004)

Found the following interesting discussion in the Newsgroups:

Strategy / direction?
by:Graham Blandford

Hi All, wonder if anyone can help me with some direction...
I'm a VB6er who has been plunged into the VB.NET arena with a requirement to
complete a reasonably small project within a month..

The basics are.. I have two databases, from 3rd-party suppliers for which
there is somewhat common data that I have to 'unite' using a simple
interface, enabling the end-user to report on the combined information from
both.

Both databases are Access; the data is 'open' in one, and the data in the
other is accesible via a dll/reference supplied by the vendor of the
software/database.

My plan is to create a 3rd database - a transaction-store, which essentially
keeps a cross-reference of records in comparable tables in the two 3rd-party
databases. A user-driven function will scan one database, and check for any
new records that don't have a matching record in the transaction-store,
these records are then presented to the user who will go then match them
with records in the other 3rd-party database. These new matches are then
added to the transaction-store database.

Now, in VB6, I could have written some quite offensive code, that would
essentially read the first table, then read the transaction-store for
existence, and added records as necessary....

Looking at VB.NET, I see that we have some wonderful ways to set
relationships in the data programmatically. Could I use this to my
advantage? If so, any code examples handy? - nothing too indepth, but any
pointers in the right direction would be greatly appreciated....

Basically, any ideas you guys have, I'd be interested in hearing... as I
say, I'm new to .NET have a number of books to read, but need to start
producing on this pretty quickly and could do with a jump-start..

Thanks,
Graham


 Reply:
by:n.b.k

 Hi Graham,
How come you don't want to use SQL statements to combined the data into
a data set that you need at run time? It would be easier then try to
replicate the two into one and then try to keep the data in sync.



 Reply:
by:William Ryan eMVP

 Hi Graham

I can't tell if the requirement is that these two old dbs are to stay in use
w/ other apps or if you simply need to use them for the data but once you
get them migrated you can say good bye to them forever. Either way you have
a pretty straightforward task. I'll explain below:
I'm going to make a few assumptions for the sake of illustration but nothign
would change if the assumptions were changed. Let's assume that both db's
have the same fields/same schemas or if not, that they are similar enough
that mapping them to a new db would be doable.

Remember that the ADO.NET metaphor is that a DataSet is roughly analagous to
a Database. A datatable is roughly analogous to a Table in that db. A
dataview is roughly equivalent to a view in a Db. A Dataset is simply a
collection of db objects, which at a minimum are 0 or more datatables.
DataTables can be bound to each other through DataRelations - these can be
defined at design time w/ Strongly typed datasets or at runtime
http://www.knowdotnet.com/articles/datarelation.html. Now, in general
strong typing is the way to go and STD's are the way to go - however if you
don't know the fields in advance, Strongly Typed Datasets (STD) don't lend
themselves well to this. Anyway, the DataAdapter object is responsible for
marshalling data back and forth. They DONT care where the data came from
and they don't care where it's going as long as the data they are moving
matches the command object for the respective command. So, lets say that
you have 100 records in table1 which has fields A, B, and C. In table 2 you
have fields A,B, C, D and E. You can use one dataadapter to fill a
datatable (dt - which is a table in a dataset dS). Now the select command
for table1 would look like Select A, B, C from Table_1. Then you'd call
fill like this OleDbDataAdapter1.Fill(ds, dt) Ok, as it stands, the
rowstate of each of the rows is 'unchanged' which means that when we call
update, it will loop through the datatable and for every row with a rowstate
of Added, it will use that row and fire the Insert Command specified in the
adapter. For each rowstate of Modified it will use the Update command. For
each row with a rowstate of Deleted it will use the delete command. Since
we don't have any changes, nothing will happen. However, if we set the
AcceptChangesDuringFill property of the adapter to false
http://www.knowdotnet.com/articles/datasetmerge.html Then all of the rows
will have a rowstate of Added. Thus, if we call update on another adapter,
each row will be treated just like it was a new row added to the set. So,
if we had OleDbDataAdapter2 and it's Insert command used only fields A, B,
and C, we could call OleDbDataAdapter2.Update(ds.Tables[0]) //tables 0 is
dt. This would effectively insert each value into the Table2. We could
also create two datatables and perhaps use merge, or add a third DataColumn
so that table1 matched 2 and use all four columns for the update. Also, you
need to use keyed tables for updates (keys on the backend at a minimum) but
you can define your own keys
http://www.knowdotnet.com/articles/dataviewspart2.html and relations that
may or may not exist on the backend. You even have .AutoIncrement
properties and a Seed and everythign.

Anyway, you can easily use both datasources to fill a datatable (yes, you
can fill one datatable with two different adapters from two (or more)
different datasources as long as the schemas match (or have something in
common - you can make them be exact or you can allow it to be forgiving to
some degreee). Now, remember that rowstate is everything. So you have all
of this data (remember the AcceptChangesDuringFill should be false if you
want these rows to be inserted into the destination) from two separate
sources in one or two datatables (say one for this). Now you can call
OleDbDataAdapter3.Update(ds.Tables[0]) or
OleDbDataAdapter3.Update(ds.Tables[0]); then call
OleDbDataAdapter3.Update(ds.Tables[1]); if we used two tables instead of
one. If you configured everything correctly, you'll have all of your data
and the modifications you made to it in the destination datasource.

This end source can be XML (you can use
DataSetName.WriteXML(@"Path:\file.xml"); to write out your data and the
inverse dataSetName.ReadXML(@"Path:\file.xml"); to deserialize things

If you look at the Data Access section of www.knowdotnet.com
http://www.knowdotnet.com/dataaccess.html I've written a fair amount of
stuff (I mention it b/c it's mine but that's in no way implying it's a
definitive site).

Bill Vaughn's www.betav.com has some of the best articles ever written on
ADO.NET, pure gold. You'll find his book(s) there too which is in a first
place tie for best ADO.NET book written. The other book is David Sceppa's
ADO.NET Core Reference. Don't leave home without either of them.

Another thing you may want to look into is System.XML and XML web services.
XML isn't the fastest way to access data but it's powerful and if you aren't
resource constrained, it offers some killer solutions.

There are many sites like www.c-sharpcorner.com that have some great
DataAccess content, of course www.dotnetjunkies.com / www.sqljunkies.com ,
www.gotdotnet.com , www.brains-n-brawn.com just to name a few. Also there
is a ton of great stuff in this NG. This is without a doubt my favorite NG
and it's because the topics are always interesting and there's some really
amazingly talented folks here.

Hopefully this is enough to get you started but if you need any help or have
any questions, please don't hesitate to ask.

Cheers,

Bill

--
W.G. Ryan MVP Windows - Embedded

www.devbuzz.com
www.knowdotnet.com
http://www.msmvps.com/williamryan/


 Reply:
by:Graham Blandford

 Thanks for your help guys.
Lots of useful things in there for me to investigate...

The .NET thing has been thrown into the mix purely because the dll/reference
for accessing one of the databases is a .NET component and can't be used in
VB6 - the database is locked up by the 3rd-party company who won't allow any
direct access to their db... so.. read only it is....hence the requirement
to develop in .NET and the aggresive time-frame to learn...

Once again, thanks for the insights and I'm sure you'll be seeing my posts
more regularly in the very near-future.... ;)

Graham


 Reply:
by:Pete Wright

 What you are saying then is that the third party has supplied a .NET
assembly (the DLL). This isn't something I know how to do off the top of my
head but I do know that you can quite easily produce a COM wrapper around a
..NET assembly. If it would help your time to market this might be a better
option; producing a COM wrapper around the assembly would for the time being
at least allow you to return to the development environment you love and
write code as you know how.

Just a thought

--
--------------------------------------------------------
Peter Wright (www.petewright.org)
Author of ADO.NET Novice To Pro
From Apress. www.apress.com



Posted by Xander Zelders
0 Comments



Peer review requested....

Found the following interesting discussion in the Newsgroups:

Peer review requested....
by:Larry Serflaten

I am planning to share a Cards.DLL out on Planet Source Code
and GotDotNet. But before I send it out to the public I would
like to get a peer review to be sure it works as intended, and
to avoid any stupid coding tricks or other unsightly practices.

I am supplying a zipped package of just the source text and
allowing the user to build all the executables. I want to be
sure that goes as planned.

To demonstrate the Cards.DLL I have included two sample programs,
a single player poker game and a quick and dirty testing form.

There is a read me file included which explains what is needed to
get it working right off, as well as documentation for the assembly.

The main thing I want looked at is the Cards project to be sure
I am not demonstrating bad practises. I'll take any and all
critiques from any of you that have a few spare minutes to
look over the code. For your effort, you can keep the poker
game! I just want to get other's opinions to be sure there are
no glaring problems with the Cards project code before posting
it to the web sites.

The zipped package is available at:
http://www.usinternet.com/users/serflaten/dotnet/games/childsplaycards.zip
(~ 195 KB)

This was developed with version 1.1 of the .Net framework, if there
are problems with other versions, I'd like to hear about it...

Thanks!
LFS


 Reply:
by:Cor Ligthert

 Hi Larry,

I have looked a little bit to your program, (Yesterday actually and what
curious what others would say before I did gave my comments)

Especially the way you make the cards was good information for me as well, I
still am thinking to make a card program myself first klaverjas (that is
ballot in french, I do not know the english name) and than bridge. The way
you make the cards was very brighten to me, while that was my major strugle,
so now I can make a new start with that again.

What I do not understand (while it is working nice) is why you did not go
for a shared class but for a module (however I see reasons).

As last, the desk is a little bit small on a desktop with smaller dots, I
would make it dynamic so that people who want to play it at office can hide
it directly for there boss and older ones at home have a simple look at it.

I did not check if your logic was working.
For a poker game I would make it more in real, with bidding and have the
change to go away and the possibility to ask for seeing, now it is for me
more a kind of black jack with a poker system.

I hope this helps?

Cor


 Reply:
by:Larry Serflaten

 

Thank you for sending your comments. replies inline:

> Especially the way you make the cards was good information for me as well, I
> still am thinking to make a card program myself first klaverjas (that is
> ballot in french, I do not know the english name) and than bridge. The way
> you make the cards was very brighten to me, while that was my major strugle,
> so now I can make a new start with that again.

Good! Does that mean you will be making your own cards?
> What I do not understand (while it is working nice) is why you did not go
> for a shared class but for a module (however I see reasons).

Would not a shared class have the same values all the time? If a card was
shared, it could only be one value at a time. That may work for drawing
purposes, but I was thinking that, like real cards, each player would be
given a set (eg. 5 for poker) to play, and they could play those one at a time.
In other words, cards are real objects, so I naturally thought to make them
objects.


> As last, the desk is a little bit small on a desktop with smaller dots,

Do you mean the poker form is a little small? Or, do you mean the cards
are small? The cards are the same size as Solitaire cards. ;-) Using the
Position property, they can be stretched to larger sizes if desired.

> I would make it dynamic so that people who want to play it at office can hide
> it directly for there boss and older ones at home have a simple look at it.

The poker game was a bonus just to show how the cards could be used.
A real poker game might have more options, I agree....
> I did not check if your logic was working.

But that is why I posted it! You were supposed to look! <g>

> For a poker game I would make it more in real, with bidding and have the
> change to go away and the possibility to ask for seeing, now it is for me
> more a kind of black jack with a poker system.

Yes, it is not a full game, it is a demo of how a programmer can use the
Card objects.

Thanks again for your comments. Do know that I have had other comments
that I want to include in the final version. I'll post a link here when a more
complete version is posted to a website. Please keep the version you have
for yourself, thanks!

LFS


 Reply:
by:Cor Ligthert

 
> > I did not check if your logic was working.
>
Your poker logic I mean.

Cor



Posted by Xander Zelders
0 Comments



System.TypeInitialisationException

Found the following interesting discussion in the Newsgroups:

System.TypeInitialisationException
by:Stefan Richter

Hi,

I developed a little program
that connects to a MS SQL Server to insert
some data.

On my PC it works perfectly,
but on all other PCs it throws an
System.TypeInitialisationException and doesn't start at all!

Before I was using ODBC to connect, now I changed to SQL Client,
but it's still not working.

Any ideas?

Thx,

Stefan



 Reply:
by:Stefan Richter

 Found the answer online:
http://www.dotnet247.com/247reference/msgs/37/189441.aspx
[...]
I ended up logging a call with Microsoft to resolve this
and it turns out that the problem lies with attaching
custom icons to the forms... as soon as the icons are
removed it compiles fine with csc!

There is a workaround - the .resx files for the forms can
be compiled to .resource files using resgen.exe and then
compiled with csc. The downside of this is that it does
not meet my requirement of being able to compile the app
using only the .Net Framework - resgen is part of Visual
Studio.
Still, at least I know what the problem is now!
[...]


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

 
Please post the questions to the groups it's related to. In your case,
that's the ADO.NET group. Your question's answer doesn't depend on
VB.NET.

--
Herfried K. Wagner [MVP]



Posted by Xander Zelders
0 Comments



Relationships using multi-column key..

Found the following interesting discussion in the Newsgroups:

Relationships using multi-column key..
by:Graham Blandford

Hi all,

Can anyone assist me? VB6er trying to delve into the world of .NET...

I have inherited a poorly designed database (access).. that uses
multi-column keys to determine parent-child relationships. Could anyone
suggest how I can handle this using a relation in VB.NET.

E.g.

Table "Area"

Year
AreaId
AreaName

has a primary key of Year and AreaId,

Table "Section" has child records of "Area";

Year
AreaId
Section
Section Name

Therefore, child records are selected as those that have the same Year and
AreaId ..

If anyone can help I'd very much appreciate it.

Thanks,
Graham Blandford


 Reply:
by:Val Mazur

 Hi,

What do you need, to create joined SQL statement or set relations between
the datatables inside of the dataset?

--
Val Mazur
Microsoft MVP


 Reply:
by:Cor Ligthert

 Hi Graham,

You mean something as this?

Cor
\\ Dim Sql As String = "SELECT * from A, B Where " & _
"A.n = B.n AND A.n = 10"
Dim Conn As New OleDbConnection(connString)
Dim da As New OleDbDataAdapter(Sql, Conn)
da.Fill(ds, "A")
da.Fill(ds, "B")
Conn.Close()
Dim drlA As New DataRelation _
("AA", ds.Tables("A").Columns("A.n"), _
ds.Tables("B").Columns("B.n"))
ds.Relations.Add(drlA)
Dim dv As New DataView(ds.Tables("A"))
DataGrid1.DataSource = dv
DataGrid1.Expand(-1)
///


 Reply:
by:William Ryan eMVP

 Hi Graham:

Cor and Val already answered it for you but i'd like to add one thing
semi-related if I may. If you look at Cor's example, that's how you join
table using a DataRelation w/ an untyped dataset.
This gives you a tremendous amount of power and flexibility and allows you
to navigate related records and perfom master-detail binding and all of that
good stuff. This is the crux of what you asked.

As an aside though, if you want to create composite keys, so that you can
find/navigate on multiple fields that may comprise a key, you can set the
PrimaryKey property of a datatable
http://www.knowdotnet.com/articles/dataviewsort.html . You should note
though that the PrimaryKey property takes an ARRAY of datacolumns, even if
that array contains just one item. It's a common mistake to set the
property to the column itself instead of an array.

Adding a Composite Key does nothing in and of itself for the problem you
originally asked about but it does allow you to enforce integrity rules and
use finds on the PrimaryKey field(s). Combined with using a dataRelation as
Cor illustrated can really allow you to do some cool stuff.

HTH,

Bill

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/



Posted by Xander Zelders
0 Comments



Help with forms

Found the following interesting discussion in the Newsgroups:

Help with forms
by:Wooten26

Ok.. extremly new to NET so bear with me )

In VB5 you could do this

(in Form2)
form1.text1.text = "test"
now how do you change textbox propertys from another part
of code - like from a module or another form?

Thanks-
Noramn


 Reply:
by:Andy Gaskell

 First you need to make sure that text1's access modifier is set to public
(Public text1 As TextBox). After you do that, Form2 just needs to have a
reference to form1 somehow. There's a few different ways they could be
related.

If Form2 is a child of form1 (code goes in Form2):
Dim myForm1 As Form1 = Me.Parent
myForm1.TextBox1.Text = "Hi from form 2!"

If Form2 is owned by form1 (code goes in Form2):
Dim myForm1 As Form1 = Me.Owner
myForm1.TextBox1.Text = "Hi from form 2!"

You can create a property on Form2 like this:
Private _myForm As Form1

Public Property MyForm() As Form1
Get
MyForm = _myForm
End Get
Set(ByVal Value As Form1)
_myForm = Value
End Set
End Property

Then you just need to make sure you set that property before you try to
access it.

Good luck!


 Reply:
by:Cor Ligthert

 Hi Wooten,

In addition to Andy.

In VB.net are 3 types of forms.
The one opened with show, the ones opened with showdialog, and the MDI forms
(parent and child)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/getstarwinform.asp

The one Andy provided you is the MDI

I hope this helps?

Cor


 Reply:
by:Armin Zingler

 
If you want to access an object, you need a reference. If you don't have
one, make it available, usually by passing the reference as a procedure
argument or to a property.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html




Posted by Xander Zelders
2 Comments



ImageList and animated Gifs

Found the following interesting discussion in the Newsgroups:

ImageList and animated Gifs
by:MrPickwick

Hi there.
If I place a picturebox on my form and load (at design time) an animated gif
into it, it shows and animates allright. If I load my animated gifs in an
Imagelist at design time and at runtime copy the image from the list into a
PictureBox using "MyPictureBox.Image = MyImageList.Images(n)" it will only
show the first frame and not animate at all.
Does this not work at all? Are there alternatives?

Thanks and regards


 Reply:
by:Brian Henry

 store the image as an embedded resource it's pretty much what image list
does anyways. then access it similar to this

dim bmp as bitmap = new
Drawing.Bitmap(gettype(classname).Assembly.GetManifestResourceStream("Namesp
ace.FileName.BMP")

(didnt verify the class names so that might be a little off)



 Reply:
by:v-phuang@online.microsoft.com (Peter Huang)

 Hi,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to stored a list of
animated gif into an imagelist and use the picturebox to show the picture
in the imagelist.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think ImageList did not support the animated gif so far. To wordaround
the problem, I think in the IDE we can add the GIFs to the project and
changed their "Build Action" property to "Embedded Resource". Then we can
read them out into an arraylist and use them similar as the imagelist.
Here goes the code.
'I add a test.gif into the project.

Dim pics As ArrayList
Dim imgStream As Stream = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
pics = New ArrayList
Dim bmp As Bitmap = Nothing
' get a reference to the current assembly
Dim a As [Assembly] = [Assembly].GetExecutingAssembly()
' get a list of resource names from the manifest
Dim resNames As String() = a.GetManifestResourceNames()
Dim s As String
For Each s In resNames
If s.EndsWith(".gif") Then
' attach to stream to the resource in the manifest
imgStream = a.GetManifestResourceStream(s)
If Not imgStream Is Nothing Then
' create a new bitmap from this stream and
' add it to the arraylist
bmp = Image.FromStream(imgStream) '
If Not bmp Is Nothing Then
pics.Add(bmp)
End If
bmp = Nothing
End If
End If
Next s
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.PictureBox1.Image = pics(0)
End Sub

Private Sub Form1_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
imgStream.Close()
imgStream = Nothing
End Sub

Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.




Posted by Xander Zelders
0 Comments



all .NET functions from VB6

Found the following interesting discussion in the Newsgroups:

call .NET functions from VB6
by:Anonymous

How can I call .NET functions like ToUInt16() from VB6? Thanks!


 Reply:
by:Armin Zingler

 
VB6 doesn't know what .NET is...
....but, you could expose your own .NET components to COM (and VB6 knows
COM):

http://msdn.microsoft.com/library/en-us/cpguide/html/cpconexposingnetframeworkcomponentstocom.asp

http://msdn.microsoft.com/library/en-us/vbcon/html/vbconCOMInteropInVisualBasicVisualC.asp

http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconCOMInteroperability.asp
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html




Posted by Xander Zelders
0 Comments



DataGrid UpperCase and Sort

Found the following interesting discussion in the Newsgroups:

DataGrid UpperCase and Sort
by:Anonymous

how to format my datagrid control for only write on it in upper case. Also i want to sort my datagrid control automatically for the column number 4. Any ideas.


 Reply:
by:Cor Ligthert

 Hi Carmen,

This I did make some weeks ago as sample for OHM

I now placed the sort in it, the sample table has only one column the
first, for a for column table you would take the right columnname.

I hope it helps as well for you?

Cor
\\\Private WithEvents dtbCol1 As DataGridTextBox
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

'This is for the sample datatable
Dim dt As New DataTable("Cor")
Dim dc As New DataColumn("OHM")
dt.Columns.Add(dc)
For i As Integer = 0 To 11
dt.Rows.Add(dt.NewRow)
dt.Rows(i)(0) = ""
Next
'Here start the grid part
Dim ts As New DataGridTableStyle
ts.MappingName = dt.TableName
Dim column As New DataGridTextBoxColumn
ts.GridColumnStyles.Add(column)
DataGrid1.TableStyles.Add(ts)
column = CType(ts.GridColumnStyles(0), DataGridTextBoxColumn)
dtbCol1 = DirectCast(column.TextBox, DataGridTextBox)
column.MappingName = dt.Columns(0).ColumnName
column.HeaderText = "OHM"
dim dv as new dataview(dt)
dv.sort = "OHM"
DataGrid1.DataSource = dv
End Sub
Private Sub dtbCol1_TextChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles dtbCol1.TextChanged
DirectCast(sender, TextBox).Text = StrConv(DirectCast(sender, _
TextBox).Text, vbUpperCase)
End Sub
///

There are more cases you can use.



Posted by Xander Zelders
0 Comments



Asynchronous Threading Help

Found the following interesting discussion in the Newsgroups:

Asynchronous Threading Help
by:slavisa@msn.com (Pug Fugly)

I am unable to call the .Show() method on a form that I have passed
through .BeginInvoke as the AsyncState parameter. I can get back the
form correctly after the .EndInvoke is called in the callback, but the
process still seems to be on a different thread even though the
..EndInvoke finished running. I get "Controls created on one thread
cannot be parented to a control on a different thread." Which I know
is not allowed, but I thought once .EndInvoke is done running I should
be back to the original thread. The form is a module variable so it
is not a scope problem. The only way I can get the form to show is if
I create a delegate for the .Show() and call that with .Invoke(). But
after that, I cannot bind to it's datagrid because I get the same
error as above. It seems like I never return back to the same thread,
or the threads are never aborting. What am I missing here?

Thanks,
Slavisa


 Reply:
by:AlexS

 Hi, Pug

After EndInvoke finished running - where are you? Because you do EndInvoke
from BeginInvoke delegate you are definitely in some thread - not the UI
one. To return to UI thread you should use form.BeginInvoke and form must
exist on UI thread.

I would suggest to trace threads using Console.WriteLine or Debug.Print -
you will see that you try to update ui form on non-ui thread. That's why you
have problem.

HTH
Alex


 Reply:
by:slavisa@msn.com (Pug Fugly)

 Thank for your suggestion Alex. You were right. The entire callback
function is in a completely different thread than the function from
where I called my .BeginInvoke. When you said "To return to UI thread
you should use form.BeginInvoke and form must exist on UI thread,"
what function did you mean that I would call the .BeginInvoke for. I
thought that .BeginInvoke can only be called on delegates, not on
forms. The form is in the UI thread which is the same thread that the
..BeginInvoke is being called from. I just need to get back to that
thread after my .EndInvoke comes back.

Thanks,
Slavisa


 Reply:
by:AlexS

 Hi, Pug - see below

If you declared say myForm on UI thread and run it there initially, say Form
myForm=new MyForm() etc.
you use myForm.BeginInvoke

Even then - check if myForm.BeginInvoke executes delegate on UI thread or
not. Depending how you get to this point it might happen you have to do one
more myForm.BeginInvoke. So, you need to pass myForm reference to async
method - or set some event in async parameters.

Main lesson - don't assume, always check which thread are you on. Then you
will be able to sort this mess fairly quickly.

HTH
Alex



Posted by Xander Zelders
1 Comments



DataSet Schema

Found the following interesting discussion in the Newsgroups:

DataSet Schema
by:Anonymous

hello to all, I have the following problem: I change a field of the data base, changes it of char(10) to char(15). The field is display in a datagrid control. When I record the information, the field only accepts the 10 characters that the field initially had, how can I do to the field of the data base takes the 15 characters that I define.


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

 
Windows Forms data binding questions go here:

<URL:news:microsoft.public.dotnet.framework.windowsforms.databinding>

Web interface:

<URL:http://msdn.microsoft.com/newsgroups/?dg=microsoft.public.dotnet.framework.windowsforms.databinding>

--
Herfried K. Wagner [MVP]


 Reply:
by:Cor Ligthert

 Herfried,

I am curious what was your idea that this had to do with binding?

Cor

> Windows Forms data binding questions go here:
>
> <URL:news:microsoft.public.dotnet.framework.windowsforms.databinding>
>
> Web interface:
>
>
<URL:http://msdn.microsoft.com/newsgroups/?dg=microsoft.public.dotnet.framew
ork.windowsforms.databinding>
>


 Reply:
by:Cor Ligthert

 Hi Carmen,

I do not know this problem, however I assume you are using the designer to
create your connection and dataadapter, did you regenerate your stronly
typed dataset using that by rightclicking on the datagrid icon in your
designer?

Cor



Posted by Xander Zelders
0 Comments



Best way to align columns when printing

Found the following interesting discussion in the Newsgroups:

Best way to align columns when printing
by:Anonymous

Hi,
Does anyone know what would be the best way to aligns columns with variable widths so that when you print them, they can all be aligned?
Thanks so much

Lisa



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

 
You can use 'Graphics.MeasureString' to get the space a string needs to
be drawn. When calling 'DrawString', you can specify the position
accordingly.

--
Herfried K. Wagner [MVP]


 Reply:
by:Anonymous

 Thanks Herfried,
I am not familiar with 'DrawString' do you have a sample code?
Thanks so much
Lisa



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

 
I am not sure how you are printing. Do you use a report engine? Then
my suggestion will not work.

For a basic printing sample without a report engine, have a look here:

<URL:http://dotnet.mvps.org/dotnet/samples/printing/downloads/PrintFramework.zip>

--
Herfried K. Wagner [MVP]


 Reply:
by:Anonymous

 Thanks Herfried.
Lisa



Posted by Xander Zelders
0 Comments



MdiOutOpen returns 'invalid param' in .NET ... but works great in VB6

Found the following interesting discussion in the Newsgroups:

1st arg must be ByRef:

ByRef lphMidiOut As Integer
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html



midiOutOpen returns 'invalid param' in .NET ... but works great in VB6
by:Anonymous

Hi all, I am hitting a roadblock with midiOutOpen from VB.Net

The code:

Declare Function midiOutOpen Lib "winmm.dll" (ByVal lphMidiOut As Integer, ByVal uDeviceID As Integer, ByVal dwCallback As Integer, ByVal dwInstance As Integer, ByVal dwFlags As Integer) As Integer

[...]

Dim hmidi As Integer
MsgBox(midiOutOpen(hmidi, -1, 0, 0, 0))

This returns the error code 11, which means invalid params. Most of the documentation I've found for midiOutOpen uses Longs for the args, but when Longs didn't work I found that VB.Net's Long is twice the width of VB6 and that Integer simulates a Long from previous languages.

This code from VB6 works correctly. I could continue to use VB6 but I have a burning desire to get this working in VB.NET:

Declare Function midiOutOpen Lib "winmm.dll" (lphMidiOut As Long, ByVal uDeviceID As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long

[...]

Dim hmidi As Long
msgbox(midiOutOpen(hmidi, -1, 0, 0, 0))

Thank you for considering my question


 Reply:
by:Armin Zingler

 
 Reply:
by:Anonymous

 !!!!Of course!!!!

Many thanks Armin.


 Reply:
by:Ken Tucker [MVP]

 Hi,

http://www.franklins.net/dotnet/CarlsMIDITools.zip

Ken



Posted by Xander Zelders
0 Comments



ado.net COM object error?!

Found the following interesting discussion in the Newsgroups:

ado.net COM object error?!
by:Anonymous

I was having problems with a piece of software I wrote on one PC. I traced it to a line of code that created an ado connection object. After reinstalling ado 2.6 and 2.7 as well as reinstalling the app, and .net framework, I was still getting the same error. So, I wrote a simple app and installer to see if the same error would occur. Sure enough it did.

The code in the sample project
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim q As New ADODB.Connection

q = Nothing
End Sub

Raises the same error: Com object with CLSID {00000514-0000-0010-8000-00AA006D2EA4} is missing or invalid. This clearly points to the ado class. But I haven't the foggiest idea what I am doing wrong.

Other info: Installing on an XP box (have instlaled on many other XP boxes successfully), logged in with administrative rights.


 Reply:
by:n.b.k

 Try using the .net reference not the COM
"Eric Fleet" <anonymous@discussions.microsoft.com> wrote in message
news:0D0B59D1-A35C-461F-B970-658FDE5EBEAD@microsoft.com...
> I was having problems with a piece of software I wrote on one PC. I traced
it to a line of code that created an ado connection object. After
reinstalling ado 2.6 and 2.7 as well as reinstalling the app, and .net
framework, I was still getting the same error. So, I wrote a simple app and
installer to see if the same error would occur. Sure enough it did.
>
> The code in the sample project
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
> Dim q As New ADODB.Connection
>
> q = Nothing
> End Sub
>
> Raises the same error: Com object with CLSID
{00000514-0000-0010-8000-00AA006D2EA4} is missing or invalid. This clearly
points to the ado class. But I haven't the foggiest idea what I am doing
wrong.
>
> Other info: Installing on an XP box (have instlaled on many other XP boxes
successfully), logged in with administrative rights.


 Reply:
by:Anonymous

 How do you do this when you have three years worth of legacy code in the form of DLLs? :)



Posted by Xander Zelders
0 Comments



Inernet explorer toolbar

Found the following interesting discussion in the Newsgroups:

internet explorer toolbar
by:Alejandro Becker

Hi, I want to create an internet explorer toolbar, like google and others.
can you tell me, please, where can I find information about this.

Thanks You

Alejandro Becker


 Reply:
by:Eric Lemmon

 Hi Alejandro,

Here are a few resources to get you started, and hopefully not overwhelm
you...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/Shell/programmersguide/shell_adv/bands.asp

http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/ext/tutorials/button.asp

http://www.codeproject.com/atl/ietoolbartutorial.asp

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=uNoiLIyWBHA.1536%40tkmsftngp05

Take care,

Eric


 Reply:
by:Alejandro Becker

 Thank you very much...
I am going to take a look at this...

Alejandro Becker


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

 

<URL:http://www.codeproject.com/csharp/dotnetbandobjects.asp>

--
Herfried K. Wagner [MVP]



Posted by Xander Zelders
0 Comments



Send email without SMTP

Found the following interesting discussion in the Newsgroups:

send email without SMTP
by:Mike

In VB6 I could send email via Outlook without using SMTP, Is it possible to
do the same in .NET and if so is there any examples of doing this?



 Reply:
by:Ken Tucker [MVP]

 Hi,

http://support.microsoft.com/default.aspx?scid=kb;en-us;313803

Ken


 Reply:
by:Gavin Jacobs

 See this:
http://msdn.microsoft.com/library/en-us/cdo/html/_olemsg_overview_of_cdo.asp?frame=true


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

 

My FAQ:

Namespace 'System.Web.Mail' (requires reference to "System.Web.dll"),
FAQ: <URL:http://www.systemwebmail.net/>.

CDO/Exchange:

Support Policy for Microsoft Exchange APIs with .NET Framework Applications
<URL:http://support.microsoft.com/?scid=kb;EN-US;813349>

HOW TO: Retrieve Messages Using CDOEX and ADO in Visual C#
<URL:http://support.microsoft.com/?scid=kb;EN-US;310206>

Self-made:

<URL:http://www.codeproject.com/csharp/karavaev_denis.asp>
<URL:http://www.codeproject.com/csharp/popapp.asp>
<URL:http://www.codeproject.com/csharp/pop3client.asp>

SMTP and POP3 Mail Server
<URL:http://www.codeproject.com/csharp/smtppop3mailserver.asp>

Commercial:

<URL:http://www.abderaware.com/mail/>

--
Herfried K. Wagner [MVP]



Posted by Xander Zelders
0 Comments



How many event handlers registered for an event

Found the following interesting discussion in the Newsgroups:

How many event handlers registered for an event
by:Marina

Hi,

Is there a way to find out if any event handlers are registered for a given
event of a given object?


 Reply:
by:Marina

 Found the answer.

You can do something like: MyEventNameEvent.GetInvokationList().Length, to
get the number of invokations that will be made. Just append 'Event', to
the name of your event (in this case, it's 'MyEventName').



Posted by Xander Zelders
0 Comments



Create TabPages at runtime (with controls)

Found the following interesting discussion in the Newsgroups:

Create TabPages at runtime (with controls)
by:Luc

Hi,

I have a TabControl and, at runtime, I need to add some tabpages. The
problem is that each tabpage is similar to the others and contains several
controls.

If I do TabControl.TabPages.Add(MyTabPage), a new BLANK tabpage is added.
How can I add in few statements a new tabpage as well as its controls
(textboxes, labels, etc.)? The first tabpage (that I create at design time)
is the "template" to be used for the other tabpages. Is there a way at
runtime to duplicate the first tabpage and create new tabpages based on this
one (including controls)? Also: how can I reference (at runtime) the newly
created tabpages and their controls?

Thanks,

Luc



 Reply:
by:Armin Zingler

 
You could create a Usercontrol and put it on the first TabPage. Then, at
runtime, create new instances of the Tabpage and the Usercontrol.

Or, derive your own class from the Tabpage class, but you won't be able to
use a designer to design it.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html




Posted by Xander Zelders
0 Comments



Modeler for .Net

Found the following interesting discussion in the Newsgroups:

Modeler for .Net
by:Anonymous

I am using VS .Net 2003 Professional Edition and I would like to model the whole arquitecture of an application with a visual tool. Which will you recomend me? I've seen some but many of them are Java oriented.

Thanks in advance,

Daniel


 Reply:
by:William Gower

 
Rational Rose XDE Modeler for .NET

http://www-306.ibm.com/software/awdtools/developer/modeler/


 Reply:
by:Anonymous

 Rose?
its horrendously expensive!
check out the Borland (yes them) 'Together' suite
or Sparx Systems 'Enterpride Architect'
both are about 10% the price of Rose...

hth guy



Posted by Xander Zelders
0 Comments



Remove vb6 compatiblilty

Found the following interesting discussion in the Newsgroups:

Remove vb6 compatiblilty
by:Anonymous




 Reply:
by:Cor Ligthert

 




Posted by Xander Zelders
0 Comments



Address of?? Or Delegate??

Found the following interesting discussion in the Newsgroups:

Address of?? Or Delegate??
by:Anonymous

If I call a sub using address of does that run the sub within a new thread via thread pool atumatically...? Or must I use a delegate to the sub then call address of delegate???


 Reply:
by:Mattias Sjögren

 
>If I call a sub using address of does that run the sub within a new thread via thread pool atumatically...?

No.
>Or must I use a delegate to the sub then call address of delegate???

You should use asynchronous delegate invocation (via BeginInvoke()) or
ThreadPool.QueueUserWorkItem().

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.



Posted by Xander Zelders
0 Comments



Posting messages inside function

Found the following interesting discussion in the Newsgroups:

Posting messages inside function
by:peter@mclinn.com (Peter)

I have a function like this:

Public Function HearThis(byval strWords as string, byValue
strTimesSaid) as string

end function

Is there anyway to input a message into the function that would be
seen in the programming enviornment? ...other than naming the
variables

IE. HearThis('do not enter in mean word myString, myCount)
-Peter


 Reply:
by:Armin Zingler

 
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html



 Reply:
by:peter@mclinn.com (Peter)

 I would like just a way of prompting the user with another message so
when they start using the function and it autocompletes the byval
information I may also insert a note.


 Reply:
by:Armin Zingler

 "Peter" <peter@mclinn.com> schrieb
> I would like just a way of prompting the user with another message

msgbox("message")

or use messagebox.show

> so when they start using the function and it autocompletes the
> byval information I may also insert a note.

The user doesn't know "ByVal" and autocomplete and so on. Where do you want
to insert a note? Sorry, I still don't understand the question.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


 Reply:
by:Chris Dunaway

 On Fri, 21 May 2004 17:41:42 +0200, Armin Zingler wrote:
I think he's referring to the tool tips that developer's see when using the
code.

Search the groups for VB Commenter, you should find what you are looking
for.

--
Chris

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.



Posted by Xander Zelders
0 Comments



SetProcessWorkingSetSize() Bad to use or good???

Found the following interesting discussion in the Newsgroups:

SetProcessWorkingSetSize() Bad to use or good???
by:Anonymous

Is it okay to call this sub so that the user see's that the app uses less memory... I thought about using this sub after form loads, it does seem to the user that the app is using less memory... Bad, Good? Doesn't matter???

Thanks,

Anthony


Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As Boolean

Public Sub SetProcessWorkingSetSize()
Try
Dim Mem As Process
Mem = Process.GetCurrentProcess()
SetProcessWorkingSetSize(Mem.Handle, -1, -1)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub


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

 
Part of the memory used by the application will be written to disk, so
performance may be reduced.

> SetProcessWorkingSetSize(Mem.Handle, -1, -1)

--
Herfried K. Wagner [MVP]



Posted by Xander Zelders
0 Comments



How to change row height in a DataGrid

Found the following interesting discussion in the Newsgroups:

How to change row height in a DataGrid
by:Tor Inge Rislaa

How to change row height in a DataGrid

I have DataGrid that is filled with data from a table in a DataSet. The
content of the cells is text of more than one line (as a note field). What I
want is to set the height of the row based on the number of lines in it. The
row height of each row in the table may be different from each other. Is
there a way to do this?

TIRislaa


 Reply:
by:Ken Tucker [MVP]

 Hi,

Here is a copy of a datagridtextboxcolumn that I am working on. It
will automatically adjust the row height based to fit the data in it. There
is a bug when you add a record it sets the all rows back to the default
height.

Imports System.Reflection

Public Class MultiLineColumn
Inherits DataGridTextBoxColumn

Private mTxtAlign As HorizontalAlignment
Private mDrawTxt As New StringFormat
Private mbAdjustHeight As Boolean = True
Private m_intPreEditHeight As Integer
Private m_rownum As Integer
Dim WithEvents dg As DataGrid
Private arHeights As ArrayList
Dim WithEvents cm As CurrencyManager

Private Sub GetHeightList()
Dim mi As MethodInfo = dg.GetType().GetMethod("get_DataGridRows",
BindingFlags.FlattenHierarchy Or BindingFlags.IgnoreCase Or
BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public Or
BindingFlags.Static)

Dim dgra As Array = CType(mi.Invoke(Me.dg, Nothing), Array)

arHeights = New ArrayList
Dim dgRowHeight As Object
For Each dgRowHeight In dgra
If dgRowHeight.ToString().EndsWith("DataGridRelationshipRow") =
True Then
arHeights.Add(dgRowHeight)
End If
Next
End Sub

Public Sub New()
mTxtAlign = HorizontalAlignment.Left
mDrawTxt.Alignment = StringAlignment.Near
'Me.ReadOnly = True
End Sub

Protected Overloads Overrides Sub Edit(ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds
As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText
As String, ByVal cellIsVisible As Boolean)

MyBase.Edit(source, rowNum, bounds, [readOnly], instantText,
cellIsVisible)
Me.TextBox.TextAlign = mTxtAlign
Me.TextBox.Multiline = mbAdjustHeight

Dim iRows As Integer
If TypeOf dg.DataSource Is DataTable Then
iRows = DirectCast(dg.DataSource, DataTable).Rows.Count
ElseIf TypeOf dg.DataSource Is DataView Then
iRows = DirectCast(dg.DataSource, DataView).Count
ElseIf TypeOf dg.DataSource Is ArrayList Then
iRows = DirectCast(dg.DataSource, ArrayList).Count
Else
iRows = DirectCast(dg.DataSource, Collection).Count
End If

Debug.WriteLine(iRows)
Debug.WriteLine(rowNum)

'If rowNum >= iRows Then
Debug.WriteLine("New Row")

For x As Integer = 0 To arHeights.Count - 1
Dim pi As PropertyInfo =
arHeights(x).GetType().GetProperty("Height")
Dim curHeight As Integer = pi.GetValue(arHeights(x), Nothing)
pi.SetValue(arHeights(x), curHeight, Nothing)
Next

Dim sz As Size = dg.Size
dg.Size = New Size(sz.Width - 1, sz.Height - 1)
dg.Size = sz
GetHeightList()

' End If

End Sub

Protected Overloads Overrides Sub Paint(ByVal g As
System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal
source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer,
ByVal backBrush As System.Drawing.Brush, ByVal foreBrush As
System.Drawing.Brush, ByVal alignToRight As Boolean)
Static bPainted As Boolean = False

If Not bPainted Then
dg = Me.DataGridTableStyle.DataGrid
GetHeightList()
End If

cm = source

'clear the cell
g.FillRectangle(backBrush, bounds)

'draw the value
Dim s As String = Me.GetColumnValueAtRow([source],
rowNum).ToString()

Dim r As New RectangleF(bounds.X, bounds.Y, bounds.Width,
bounds.Height)

r.Inflate(0, -1)

' get the height column should be
Dim sDraw As SizeF = g.MeasureString(s, Me.TextBox.Font, Me.Width,
mDrawTxt)
Dim h As Integer = sDraw.Height + 15

If mbAdjustHeight Then

Try
Dim pi As PropertyInfo =
arHeights(rowNum).GetType().GetProperty("Height")
' get current height
Dim curHeight As Integer = pi.GetValue(arHeights(rowNum),
Nothing)

' adjust height

If h > curHeight Then
pi.SetValue(arHeights(rowNum), h, Nothing)
Dim sz As Size = dg.Size
dg.Size = New Size(sz.Width - 1, sz.Height - 1)
dg.Size = sz
End If

Catch
' something wrong leave default height
GetHeightList()
End Try
End If

g.DrawString(s, MyBase.TextBox.Font, foreBrush, r, mDrawTxt)
bPainted = True
End Sub

Public Property DataAlignment() As HorizontalAlignment
Get
Return mTxtAlign
End Get
Set(ByVal Value As HorizontalAlignment)
mTxtAlign = Value
If mTxtAlign = HorizontalAlignment.Center Then
mDrawTxt.Alignment = StringAlignment.Center
ElseIf mTxtAlign = HorizontalAlignment.Right Then
mDrawTxt.Alignment = StringAlignment.Far
Else
mDrawTxt.Alignment = StringAlignment.Near
End If
End Set
End Property

Public Property AutoAdjustHeight() As Boolean
Get
Return mbAdjustHeight
End Get
Set(ByVal Value As Boolean)
mbAdjustHeight = Value
Try
dg.Invalidate()
Catch
End Try
End Set
End Property

Private Sub cm_PositionChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cm.PositionChanged
Static intOld As Integer = 0
'If intOld > cm.Position Then
If cm.Count > DirectCast(dg.DataSource, DataTable).Rows.Count Then
Debug.WriteLine("New Row")

For x As Integer = 0 To arHeights.Count - 1
Dim pi As PropertyInfo =
arHeights(x).GetType().GetProperty("Height")
Dim curHeight As Integer = pi.GetValue(arHeights(x),
Nothing)
pi.SetValue(arHeights(x), curHeight, Nothing)
Next

Dim sz As Size = dg.Size
dg.Size = New Size(sz.Width - 1, sz.Height - 1)
dg.Size = sz
End If

intOld = cm.Position
End Sub
End Class
Ken



Posted by Xander Zelders
0 Comments



Using AddressOf... as a parameter

Found the following interesting discussion in the Newsgroups:

First, define the delegate that matches the signature of what you want
to call:

Public Delegate Sub ShowStatusDelegate(newStatus As String)

This defines a delegate called "ShowStatusUpdate". It's signature is
basically:
1) A Sub
2) Accepts one string parameter

Now you need to define the actual procedure that you want pass via
AddressOf. It must match the signature above in your delegate (sub with
one string parameter)

Public Sub ShowStatus(data As String)
statusLable.Text = data
End Sub

Now, the method that accepts your 'AddressOf' parameter needs to accept
a type of "ShowStatusDelegate":

Public Sub foo(func As ShowStatusDelegate)
...
End Sub

Now you can call:

foo(AddressOf Me.ShowStatus)

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele


Using AddressOf... as a parameter
by:Anthony Coelho

Hello Guru's!

I am trying to pass a function pointer as a parameter to a method and can't
seem to get it working. Basically I want to do the exact same thing that the
System.Threading.Thread constructor does in VB.NET within my own class. In
the Thread constructor, you can specify the function to run instead of
creating a ThreadStart object by using the AddressOf keyword such as; Dim
oThread As New Threading.Thread(AddressOf foo.Run)

I have a method that I would like to do the exact same thing as, but what do
you declare the type as? I've tried a delegate, but that's not working for
me. For example, say you have the following method:

Public foo(mydelegate as System.Delegate)

If you call this method passing a function pointer such as
myClass.foo(AddressOf myfunction.DoSomething) you get the following error:

'AddressOf' expression cannot be converted to 'System.Delegate' because
'System.Delegate' is not a delegate type.

How's that for a error? System.Delegate is not a delegate type? Are you as
confused on this as I am? So to wrap, does anyone know how I can pass a
function pointer into a method as a parameter just like the Threading.Thread
constructor allows?

Cheers,
Anthony


 Reply:
by:Ken Tucker [MVP]

 Hi,

Create a delegate function. Have the delegate function as the type
of the parameter passed in to the procedure. Here is an quick example.

Delegate Function MyFooCallBack(ByVal MyArugments As Integer) As Integer

Public foo(mydelegate as MyFooCallback)

http://www.elitevb.com/content/01,0075,01/04.aspx
Ken


 Reply:
by:Patrick Steele [MVP]

 

Posted by Xander Zelders
0 Comments



How to access .Net Assembly from another Workstation?

Found the following interesting discussion in the Newsgroups:

How to access .Net Assembly from another Workstation?
by:IMRAN SAROIA

Hi!

I have developed a simple database (using oledb and Access ) application in
VB.Net. I have placed the Assembly (EXE) on server computer and want to
access the application from other workstations. When ever databound form is
going to be displayed security exception about access denied is thrown.

Please advise.

This never happened with unmanaged code.

Regards

Imran



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

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

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


 Reply:
by:Marc Butenko

 The problem is that by default, .NET security running across the network
does not allow File I/O. So, you need to give the assembly trust (by using
the .NET Framework Wizards in Administrative Tools). There are other ways
to do this too, such as using CASPOL.EXE to modify the security policy.

Here is a couple articles that might help:
http://support.microsoft.com/default.aspx?scid=kb;en-us;832742
http://support.microsoft.com/default.aspx?scid=kb;EN-US;815164
http://support.microsoft.com/default.aspx?scid=kb;en-us;837909

--
Marc Butenko
mbutenko@bresnan.net



Posted by Xander Zelders
0 Comments



Help files

Found the following interesting discussion in the Newsgroups:

Help files
by:Brian Henry

Now in VS.NET how do you create help files? we use to have a help workshop
to do it but I don't see it, what is the process now? thanks


 Reply:
by:Armin Zingler

 

http://msdn.microsoft.com/library/en-us/vbcon/html/vbconApplicationAssistance.asp

(also available by <F1>)
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html



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

 * "Brian Henry"

<URL:http://www.mvps.org/htmlhelpcenter/htmlhelp/hhvbnet.html>

AFAIR the 101 VB.NET samples included a sample for creating a HTML Help
help file and associating it with a VB.NET application:

<URL:http://www.microsoft.com/downloads/details.aspx?FamilyId=08E3D5F8-033D-420B-A3B1-3074505C03F3&displaylang=en>

The HTML Help Workshop is included with some versions of VS.NET.

It's a free tool, you can download it from the Microsoft Homepage:

Microsoft HTML Help Downloads
<URL:http://msdn.microsoft.com/library/en-us/htmlhelp/html/hwMicrosoftHTMLHelpDownloads.asp>

--
Herfried K. Wagner [MVP]


 Reply:
by:Brian Henry

 thanks for the links, that was what i was looking for


 Reply:
by:Ulrich Kulle

 Hallo Brian,


If you are interested in help authoring and .net, have a look at the following
internet links:

http://www.help-info.de/en/Visual_Basic_net/visual_basic_net.htm

http://www.mshelpwiki.com/index.php?page=HTMLHelpArticles

HTH

Best regards
Ulrich Kulle
***************************************
http://www.help-info.de
***************************************



Posted by Xander Zelders
0 Comments



Re: multiple search/replacements in a single Regex.Replace?

Found the following interesting discussion in the Newsgroups:

Re: multiple search/replacements in a single Regex.Replace?
by:Jay B. Harlow [MVP - Outlook]

D'oh!,
I cut & pasted info on Split, when I meant to include info on Replace. :-))

The same thought applies, there are four Replace functions in .NET:

I would use Microsoft.VisualBasic.Strings.Replace when I needed the extra
options that it offered .
I would use System.String.Replace when I only had one replacement to do
based on a single character or specific word.
I would use System.Text.StringBuilder.Replace when I had multiple
replacements to do based on single characters or specific words. Where the
characters or word replacements were 1 for 1.
I would use System.Text.RegularExpressions.RegEx.Replace when I needed to
replace based on varying patterns. For example replace repeating white space
with a comma.

Hope this helps
Jay


 Reply:
by:Cor Ligthert

 Hi Jay,

I was already thinking, did I do all that testing for nothing

:-)

Cor


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

 Cor,
Remember I only concern myself with performance, once a routine has proven,
via profiling, to have performance issues...

Jay



Posted by Xander Zelders
0 Comments



Database app for xda II

Found the following interesting discussion in the Newsgroups:

Database app for xda II
by:John

Hi

We have a .net database app with MS Access backend running in house over a
windows 2000 server network. Is it possible to re-write the same app for xda
ii (http://www.xda-2.co.uk/under_the_bonnet.html) /windows mobile 2003 that
can updated data from/to server? What means can be used to update the data
(gprs?)? Is it too difficult to do this for someone with strong database
skills i.e. does gprs etc. require a lot of knowledge of the underlying
technology with a need to write code around it?

If access is a problem then we can move to SQL Server, but is this at all
possible?

Thanks

Regards



 Reply:
by:Cor Ligthert

 Hi John,

When you have luck William Ryan answers this question here, however there
are probably more active who knows about yyour questions

microsoft.public.dotnet.framework.compactframework.

I hope your finds your solution.

Cor



Posted by Xander Zelders
0 Comments



Hard Drive Low in "Space" event !

Found the following interesting discussion in the Newsgroups:

Hard Drive Low in "Space" event !
by:Eddie

Hi All,

I would like to write a windows service that will "Check" any problems on my
computer. For exemple, I would like to pop up a windows if my Hard drive is
low in "space" (maybe 5 % free space). How may I do it ? Does VS.NET provide
a tools for that...
I also would like, for exemple, know if my CPU temperature is too high, or
if my Laptop battery is too "low"...

Any help ?

Regards,

Eddie


 Reply:
by:Cor Ligthert

 Hi Eddie,

Some things are easy to do when you use the management class
(WMI)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemManagementManagementClassClassTopic.asp
However not all.

I hope this helps?

Cor


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

 * "Eddie"
I doubt that.

> I also would like, for exemple, know if my CPU temperature is too high, or
> if my Laptop battery is too "low"...

WMI + 'Win32_TemperatureProbe'.

<URL:http://www.google.de/groups?selm=uk%23UD5APDHA.3664%40tk2msftngp13.phx.gbl>

For the battery, cou can translate this VB6 sample to VB.NET:

<URL:http://www.shadoware.de/files/vb/powerstatus.zip>

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


 Reply:
by:Eddie

 Thank you... where can I find a complete list of "ManagementClass" like
'Win32_TemperatureProbe' or Win32_LogicalDisk ?


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

 * "Eddie"
<URL:http://msdn.microsoft.com/library/en-us/wmisdk/wmi/computer_system_hardware_classes.asp>

--
Herfried K. Wagner [MVP]



Posted by Xander Zelders
0 Comments



VB.NET Error .... details explained inside. HELP!!!

Found the following interesting discussion in the Newsgroups:

VB.NET Error .... details explained inside. HELP!!!
by:D P

Hello everyone, I am new here and I hope I can get the help I need.

I will be as descriptive as possible!!

I have developed an app using VB.NET that requires making a connection
to an access DB that sits on the same machine in which the app is
running. First off, this works PERFECTLY on my PC, but not on the PC
where it will be running.

It needs to open the local database and generate a snapshot of the
report that is specified ( .... the report DOES exist in the DB by the
same name that is used in code).
Here is the code snippet....
(I am using Northwind.mdb as a test DB!!!)

=============================================

Dim oAccess As Access.Application
Dim sDBPath As String 'path to DB
Dim sReport As String
'Testing
sReport = "Summary of Sales by Year"

' Start a new instance of Access for Automation:
oAccess = New Access.Application
sDBPath = "C:\NorthWindODBC\NorthWind.mdb"

***** Error occurs here on OpenDatabase *****
oAccess.OpenCurrentDatabase(filepath:=sDBPath, Exclusive:=False)

oAccess.DoCmd.Minimize()

oAccess.Visible = False

'Output in snapshot format to a temp file

oAccess.DoCmd.OutputTo(Access.AcOutputObjectType.acOutputReport,
sReport, "Snapshot Format", "C:\NorthWindODBC\temp.snp", False)
'Quit access
oAccess.Quit()

'Free
oAccess = Nothing
==============================================

This works as I mentioned on my PC but not on the PC where it will be
running.

I have dloaded and installed the .NET Framework on the target PC,
installed the latest MDAC.

I have copied the exe and reference file dlls from the bin folder of my
project folder to the target PC ... nothing works. Even creating setup
and installing it.

My PC is Windows XP, and Target is Windows 2000!
The error I get is .....

system.nullreferenceexception: Object Reference not set to an instance
of an object

This error is occuring on the line I indicated above (***)

Any ideas?? Thanks in advance to anyone with any ideas on how to solve
this!
OH .... and I have set permissions and things like that on the DB itself
and the folder where it is located!

*** Sent via Developersdex http://www.developersdex.com ***
Don't j