I need some help in translating from VB4 to VB.NET

  • Thread starter Thread starter kurt
  • Start date Start date
K

kurt

I have a program I’ve written in VB-4 and am now trying to re-write in VB..NET 2005
Some of what I can’t seem to figure out is how do I transcribe the following VB-6 code to run in my VB.NET program, any and all help is appreciated.Thank you.
'*************************************************
' Keep within screen viewing
Dim maxNormalWidth As Long, maxNormalHeight As Long
Dim deskArea As RECT
Call SystemParametersInfo(SPI_GETWORKAREA, 0&, deskArea, 0&)
deskArea.Left = ScaleX(deskArea.Left, vbPixels, vbTwips)
deskArea.Top = ScaleY(deskArea.Top, vbPixels, vbTwips)
deskArea.Right = ScaleX(deskArea.Right, vbPixels, vbTwips)
deskArea.Bottom = ScaleY(deskArea.Bottom, vbPixels, vbTwips)
maxNormalWidth = (deskArea.Right - deskArea.Left)
maxNormalHeight = (deskArea.Bottom - deskArea.Top)
If Me.Width > maxNormalWidth Then
Me.Width = maxNormalWidth
End If
If Me.Height > maxNormalHeight Then
Me.Height = maxNormalHeight
End If
Me.Left = deskArea.Left + (deskArea.Right - deskArea.Left - Me.Width) /2
Me.Top = deskArea.Top + (deskArea.Bottom - deskArea.Top - Me.Height) / 2
'**************************************************
 
Much of the code you posted would be exactly the same between the two environments. How about you describe specifically what part of the translationyou are having trouble with? Are you getting errors? Are you having trouble finding specific utility functions? What _precisely_ is the difficulty you're having?
---------------------------------------------------------------------------------

Thanks for your reply. How would I declare scaleX, scaleY, VBpixels, VBtwips
and if I was to hard code placement of form1 for instance how is that done.

example if VB is;
' Me.Left = (Form1.Left + (Form1.Width / 2) - Me.Width / 2)
' Me.Top = (Form1.Top + (Form1.Height / 2) - Me.Height / 2)
 
Dim deskArea as System.Drawing.Rectangle deskArea = System.Forms.Screen..PrimaryScreen.WorkingArea If Me.Width > deskArea.Width Then Me.Width = deskArea.Width End If If Me.Height > deskArea.Height Then Me.Height = deskArea.Height End If Me.Left = deskArea.Left + (deskArea.Width - Me.Width) / 2 Me.Right = deskArea.Top + (deskArea.Height - Me.Height) / 2 Hope thathelps.
 
Dim deskArea as System.Drawing.Rectangle

deskArea = System.Forms.Screen.PrimaryScreen.WorkingArea

If Me.Width > deskArea.Width Then
Me.Width = deskArea.Width
End If

If Me.Height > deskArea.Height Then
Me.Height = deskArea.Height
End If

Me.Left = deskArea.Left + (deskArea.Width - Me.Width) / 2
Me.Right = deskArea.Top + (deskArea.Height - Me.Height) / 2
----------------------------------------------------------------------------

I'm actually getting two errors.
it's saying that "Forms" is not a member of "System"
and
"Right" is "ReadOnly"
Hope that helps.
 
error Sorry. That should be "Me.Top", not "Me.Right" (as in the original code). You will find it helpful in the future to take the time to interpretthe code and get to a point where you understand what it's actually supposed to do. Then you can avoid getting tripped up by simple typographical errors like that one. :)
 
Can you show me how
Drive = App.Path & "\User_Files\profile.bda" would be written for VB.NET
App.path
Thanks for your help Peter Duniho.
 
-------------------------------------------------------------------------------

Thank you Peter, I will do some studying on these links you've provided. Thanks again.
 
Can someone explain to me what this error means. I'm new to VB.NET

Error 1 Variable 'deskArea' hides a variable in an enclosing block.
 
"hides" means that you used the same name for a different variable. "in an enclosing block" means that the different variable is declared in a block of code containing the block in which the error-producing declaration is found.
 
What I can't seem to figure out now is translating something like the code below.

Open Drive For Input As #1
Open Drive2 For Output As #2
Do While Not EOF(1)
Input #1, dat1, dat2, dat3, dat4
Write #2, dat1, dat2, dat3, dat4
Loop
Close #1
Close #2

Can someone assist me? thank you in advance.
 
Back
Top