|
I'm using visual basic 6 and am having problems adding an icon for my project. Every time i try to add an icon to my project, i get an error. Any help would be appreciated.
Jeff
|
|
|
|
|
Member 13982471 wrote: Every time i try to add an icon to my project, i get an error. We cannot guess a) what you are doing to try to add it, or b) what error you get when you do whatever it is you do.
|
|
|
|
|
I got the icon problem fixed. Thank you all for your input.
Jeff
|
|
|
|
|
Try adding an icon that is max 32x32 pixels, and has no more than 16 colors.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
And give the poor bloody thing a walking stick.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
A silver bullet may be more appropriate.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi, I have the following code which was posted online by a user on another forum under the MIT licence. It's a custom control which is intended to replace the rather limited FolderBrowserDialog control. It works very well with the exception of one problem as far as I can see. It won't let me specify the InitialFolder property or DefaulyFolder property without throwing a really complex looking error.
Here's the code...
Imports System
Imports System.IO
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Public Class OpenFolderDialog
Implements IDisposable
' Gets/sets folder in which dialog will be open.
Public Property InitialFolder() As String
Get
Return m_InitialFolder
End Get
Set(ByVal value As String)
m_InitialFolder = value
End Set
End Property
Private m_InitialFolder As String
' Gets/sets directory in which dialog will be open if there is no recent directory available.
Public Property DefaultFolder() As String
Get
Return m_DefaultFolder
End Get
Set(ByVal value As String)
m_DefaultFolder = value
End Set
End Property
Private m_DefaultFolder As String
' Gets selected folder.
Public Property Folder() As String
Get
Return m_Folder
End Get
Private Set(ByVal value As String)
m_Folder = value
End Set
End Property
Private m_Folder As String
Public Function ShowDialog(ByVal owner As IWin32Window) As DialogResult
If Environment.OSVersion.Version.Major >= 6 Then
Return ShowVistaDialog(owner)
Else
Return ShowLegacyDialog(owner)
End If
End Function
Private Function ShowVistaDialog(ByVal owner As IWin32Window) As DialogResult
Dim frm = DirectCast(New NativeMethods.FileOpenDialogRCW(), NativeMethods.IFileDialog)
Dim options As UInteger
frm.GetOptions(options)
options = options Or NativeMethods.FOS_PICKFOLDERS Or NativeMethods.FOS_FORCEFILESYSTEM Or NativeMethods.FOS_NOVALIDATE Or NativeMethods.FOS_NOTESTFILECREATE Or NativeMethods.FOS_DONTADDTORECENT
frm.SetOptions(options)
If Me.InitialFolder IsNot Nothing Then
Dim directoryShellItem As NativeMethods.IShellItem
Dim riid = New Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")
'IShellItem
If NativeMethods.SHCreateItemFromParsingName(Me.InitialFolder, IntPtr.Zero, riid, directoryShellItem) = NativeMethods.S_OK Then
frm.SetFolder(directoryShellItem)
End If
End If
If Me.DefaultFolder IsNot Nothing Then
Dim directoryShellItem As NativeMethods.IShellItem
Dim riid = New Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")
'IShellItem
If NativeMethods.SHCreateItemFromParsingName(Me.DefaultFolder, IntPtr.Zero, riid, directoryShellItem) = NativeMethods.S_OK Then
frm.SetDefaultFolder(directoryShellItem)
End If
End If
If frm.Show(owner.Handle) = NativeMethods.S_OK Then
Dim shellItem As NativeMethods.IShellItem
If frm.GetResult(shellItem) = NativeMethods.S_OK Then
Dim pszString As IntPtr
If shellItem.GetDisplayName(NativeMethods.SIGDN_FILESYSPATH, pszString) = NativeMethods.S_OK Then
If pszString <> IntPtr.Zero Then
Try
Me.Folder = Marshal.PtrToStringAuto(pszString)
Return DialogResult.OK
Finally
Marshal.FreeCoTaskMem(pszString)
End Try
End If
End If
End If
End If
Return DialogResult.Cancel
End Function
Private Function ShowLegacyDialog(ByVal owner As IWin32Window) As DialogResult
Using frm = New SaveFileDialog()
frm.CheckFileExists = False
frm.CheckPathExists = True
frm.CreatePrompt = False
frm.Filter = "|" & Guid.Empty.ToString()
frm.FileName = "any"
If Me.InitialFolder IsNot Nothing Then
frm.InitialDirectory = Me.InitialFolder
End If
frm.OverwritePrompt = False
frm.Title = "Select Folder"
frm.ValidateNames = False
If frm.ShowDialog(owner) = DialogResult.OK Then
Me.Folder = Path.GetDirectoryName(frm.FileName)
Return DialogResult.OK
Else
Return DialogResult.Cancel
End If
End Using
End Function
Public Sub Dispose() Implements IDisposable.Dispose
End Sub
'just to have possibility of Using statement.
End Class
Friend Module NativeMethods
#Region "Constants"
Public Const FOS_PICKFOLDERS As UInteger = &H20
Public Const FOS_FORCEFILESYSTEM As UInteger = &H40
Public Const FOS_NOVALIDATE As UInteger = &H100
Public Const FOS_NOTESTFILECREATE As UInteger = &H10000
Public Const FOS_DONTADDTORECENT As UInteger = &H2000000
Public Const S_OK As UInteger = &H0
Public Const SIGDN_FILESYSPATH As UInteger = &H80058000UI
#End Region
#Region "COM"
<ComImport(), ClassInterface(ClassInterfaceType.None), TypeLibType(TypeLibTypeFlags.FCanCreate), Guid("DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7")>
Friend Class FileOpenDialogRCW
End Class
<ComImport(), Guid("42F85136-DB7E-439C-85F1-E4075D135FC8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Friend Interface IFileDialog
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
<PreserveSig()>
Function Show(<[In](), [Optional]()> ByVal hwndOwner As IntPtr) As UInteger
'IModalWindow
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function SetFileTypes(<[In]()> ByVal cFileTypes As UInteger, <[In](), MarshalAs(UnmanagedType.LPArray)> ByVal rgFilterSpec As IntPtr) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function SetFileTypeIndex(<[In]()> ByVal iFileType As UInteger) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function GetFileTypeIndex(ByRef piFileType As UInteger) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function Advise(<[In](), MarshalAs(UnmanagedType.[Interface])> ByVal pfde As IntPtr, ByRef pdwCookie As UInteger) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function Unadvise(<[In]()> ByVal dwCookie As UInteger) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function SetOptions(<[In]()> ByVal fos As UInteger) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function GetOptions(ByRef fos As UInteger) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Sub SetDefaultFolder(<[In](), MarshalAs(UnmanagedType.[Interface])> ByVal psi As IShellItem)
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function SetFolder(<[In](), MarshalAs(UnmanagedType.[Interface])> ByVal psi As IShellItem) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function GetFolder(<MarshalAs(UnmanagedType.[Interface])> ByRef ppsi As IShellItem) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function GetCurrentSelection(<MarshalAs(UnmanagedType.[Interface])> ByRef ppsi As IShellItem) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function SetFileName(<[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal pszName As String) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function GetFileName(<MarshalAs(UnmanagedType.LPWStr)> ByRef pszName As String) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function SetTitle(<[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal pszTitle As String) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function SetOkButtonLabel(<[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal pszText As String) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function SetFileNameLabel(<[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal pszLabel As String) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function GetResult(<MarshalAs(UnmanagedType.[Interface])> ByRef ppsi As IShellItem) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function AddPlace(<[In](), MarshalAs(UnmanagedType.[Interface])> ByVal psi As IShellItem, ByVal fdap As UInteger) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function SetDefaultExtension(<[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal pszDefaultExtension As String) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function Close(<MarshalAs(UnmanagedType.[Error])> ByVal hr As UInteger) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function SetClientGuid(<[In]()> ByRef guid As Guid) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function ClearClientData() As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function SetFilter(<MarshalAs(UnmanagedType.[Interface])> ByVal pFilter As IntPtr) As UInteger
End Interface
<ComImport(), Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Friend Interface IShellItem
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function BindToHandler(<[In]()> ByVal pbc As IntPtr, <[In]()> ByRef rbhid As Guid, <[In]()> ByRef riid As Guid, <Out(), MarshalAs(UnmanagedType.[Interface])> ByRef ppvOut As IntPtr) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function GetParent(<MarshalAs(UnmanagedType.[Interface])> ByRef ppsi As IShellItem) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function GetDisplayName(<[In]()> ByVal sigdnName As UInteger, ByRef ppszName As IntPtr) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function GetAttributes(<[In]()> ByVal sfgaoMask As UInteger, ByRef psfgaoAttribs As UInteger) As UInteger
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)>
Function Compare(<[In](), MarshalAs(UnmanagedType.[Interface])> ByVal psi As IShellItem, <[In]()> ByVal hint As UInteger, ByRef piOrder As Integer) As UInteger
End Interface
#End Region
<DllImport("shell32.dll", CharSet:=CharSet.Unicode, PreserveSig:=False)>
Public Function SHCreateItemFromParsingName(
<MarshalAs(UnmanagedType.LPWStr)> ByVal pszPath As String,
ByVal pbc As IntPtr,
<MarshalAs(UnmanagedType.LPStruct)> ByVal riid As Guid,
<MarshalAs(UnmanagedType.Interface, IidParameterIndex:=2)> ByRef ppv As IShellItem) As Integer
End Function
End Module
Here's how to call a new instance...
Using frm = New OpenFolderDialog()
frm.InitialFolder = "E:\"
frm.DefaultFolder = "E:\"
If frm.ShowDialog(Me) = DialogResult.OK Then
MessageBox.Show(Me, frm.Folder)
End If
End Using
This is the exception error I'm getting...
WindowsApplication1.NativeMethods::SHCreateItemFromParsingName' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.'
Many thanks.
|
|
|
|
|
You're going to have to go back to the person who wrote that code and ask him/her. I don't have the time to dig into this.
An unbalanced stack is usually caused by parameter types being declared and passed incorrectly from what Windows expects. Specifically, the problem is going to be rooted in this line:
<DllImport("shell32.dll", CharSet:=CharSet.Unicode, PreserveSig:=False)>
Public Function SHCreateItemFromParsingName(
<MarshalAs(UnmanagedType.LPWStr)> ByVal pszPath As String,
ByVal pbc As IntPtr,
<MarshalAs(UnmanagedType.LPStruct)> ByVal riid As Guid,
<MarshalAs(UnmanagedType.Interface, IidParameterIndex:=2)> ByRef ppv As IShellItem) As Integer
End Function
|
|
|
|
|
pinvoke.net: SHCreateItemFromParsingName (shell32)[^]
The example there does not have the "As Integer" part at the end of the declaration.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
Good catch
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi
I am trying to find a way of displaying SVG within Visual Basic 6, you could at one point use Adobe Viewer 3 - but not longer.
I have managed to self create a HTML page, launch the assocaited web browser to show it, then i capture the screen - however the screen is captured but without the image being shown on it, yet the image is on the web page, if i do a normal screen capture - i can get the image.
All i am actually looking to do is to show the svg image within our vb application - which sadly it is written in vb6 and is far too big to change over.
I have looked into the SVG and in theroy could write an XML parser to read in and display but it makes sense to use the inbuilt browser control as they get updated.
Any suggestions ?
|
|
|
|
|
The web browser control uses Internet Explorer. By default, it's stuck in IE7 mode unless you change the registry on every computer that runs your application:
Web Browser Control & Specifying the IE Version - Rick Strahl's Web Log[^]
IE didn't add support for SVG until v8:
Can I use... Support tables for HTML5, CSS3, etc[^] (Click "Show all" to see the old versions.)
Even if you can force the control to use the latest rendering mode, you may still need some workarounds for the bugs:
Test Scaling Of SVG Images In Fluid Layouts[^]
Do you need to resize the SVG image? If not, it would make more sense to convert it to an image format that VB6 supports.
NB: VB6 has been "dead" for almost two decades now. Whilst the application will still work, you'll struggle to support any new API or technology created in this millennium, and you'll find it increasingly difficult to get help for any issues. It may be time to re-evaluate the "too big to change" decision.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
support for *.svg-files is quite limited on Windows operating systems. So while I would normally advise to keep your vb6 code free of dependencies, in this case it is not possible to do without. However, since you are using a "real" programming language such as vb6 , you're in luck:
Have a look at Avax Vector ActiveX (OCX)
This library will add a lot more than just *.svg support and you'll find proper vb6 example code on the page - so you should be up and running within an hour.
Another approach, depending on how much effort you want to invest, would be to use the vbRichClient-Framework which uses cairo as a forms rendering engine: *.svg loading and saving is build right in and vbRichClient.dll is a rather well-performing and light-weight library - and since you'll have to distribute vbrun.dll anyway...
Btw. I wouldn't pay any notice to people trying to get you to "migrate" you to a "up-to-date platform". Chances are, these folks have never used vb6 anyway - and thus don't know how it has envolved in the last 20 years. As long as Windows is based mostly on COM, any managed code will look very poor indeed when compared to vb6.
|
|
|
|
|
Linking to commercial products is spam, and will not be tolerated. Your "Avax Vector ActiveX" library costs $380.
wrote: Chances are, these folks have never used vb6 anyway - and thus don't know how it has envolved in the last 20 years.
You know what they say about assumptions. Lots of us have suffered through using VB6 back when it was an active language. And it has been officially dead for almost 20 years, so it won't have "evolved" much.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Phooey. VB6 was and still is by far a better programming tool than any of that bloated and messy .NET crap.....
|
|
|
|
|
Hi everyone.
I think this might be my first post here. I rarely post questions, normally I like to search for my answers but this I thought I try to ask here.
Anyway, I noticed something that I found strange while using lists and For loops.
I'm pasting an example code here:
What it does is trying to scale rectangles saved within a list using loops.
Sub TestForLoop()
Dim lstRectangles As New List(Of Rectangle)
lstRectangles.Add(New Rectangle(100, 200, 1000, 2000))
lstRectangles.Add(New Rectangle(500, 700, 1500, 2000))
Dim gScale As Single = 0.1
ShowRectDimensions("Before scaling: ", lstRectangles)
Debug.WriteLine("")
For Each rect As Rectangle In lstRectangles
With rect
rect = New Rectangle(CInt(.Left * gScale), CInt(.Top * gScale),
CInt(.Width * gScale), CInt(.Height * gScale))
Debug.WriteLine("Result inside For Each Loop: {0}x{1},{2}x{3}", .Left, .Top, .Width, .Height)
End With
Next
ShowRectDimensions("Result outside For Each Loop: ", lstRectangles)
Debug.WriteLine("")
For i As Integer = 0 To lstRectangles.Count - 1
With lstRectangles(i)
lstRectangles(i) = New Rectangle(CInt(.Left * gScale), CInt(.Top * gScale),
CInt(.Width * gScale), CInt(.Height * gScale))
Debug.WriteLine("Result inside For Next Loop: {0}x{1},{2}x{3}", .Left, .Top, .Width, .Height)
End With
Next
ShowRectDimensions("Result outside For Next Loop: ", lstRectangles)
Debug.WriteLine("")
End Sub
Private Sub ShowRectDimensions(sText As String, lstRectangles As List(Of Rectangle))
For Each rect As Rectangle In lstRectangles
With rect
Debug.WriteLine("{0}{1}x{2},{3}x{4}", sText, CStr(.Left), CStr(.Top), CStr(.Width), CStr(.Height))
End With
Next
End Sub
This produces this result in the debug window:
Before scaling: 100x200,1000x2000
Before scaling: 500x700,1500x2000
Result inside For Each Loop: 10x20,100x200
Result inside For Each Loop: 50x70,150x200
Result outside For Each Loop: 100x200,1000x2000
Result outside For Each Loop: 500x700,1500x2000
Result inside For Next Loop: 100x200,1000x2000
Result inside For Next Loop: 500x700,1500x2000
Result outside For Next Loop: 10x20,100x200
Result outside For Next Loop: 50x70,150x200
As you can see, while being on the inside of a for each loop the changes to the elements is readable and reusable. But when getting on the outside it is clear that none of the changes got saved back to the list.
However, when using the traditional For Next loop, no changes can be seen to the list until you get to the outside. This is the opposite behaviour.
This just feels weird and forces me to copy the value when I want to do more advanced calculations and the write it back to the item after. And as far as I can see the Inumerable loop seems worthless when wanting to write data back..
Am I doing something wrong or is there a logic to this?
[Edited a typo..]
modified 9-Sep-18 7:09am.
|
|
|
|
|
The Current property of the enumerator object is ReadOnly, and it returns a local copy of each collection element. This means that you cannot modify the elements themselves in a For Each...Next loop. Any modification you make affects only the local copy from Current and isn't reflected back into the underlying collection. However, if an element is a reference type, you can modify the members of the instance to which it points. Imagine a for-next to make a copy of the list; if you have reference-type objects in there (objects), then you can modify the properties of the object (only the pointer to object is readonly, not its properties). That doesn't work for value-types.
Use an object instead of a Rectangle, and things will work as you expected. If you want to keep using Rectangle (which is cheaper in terms of resource-usage) you'd limit yourself to For..Next loops.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Oh great..
I fell for the byval mistake... again.
Of course that's why the elements was a copy. I was so sure this had worked before but obviously with reference objects.
Thank's for pointing this out, Eddy!
I should have realised this but when it failed me I just switched to a For..Next loop and ran into the next problem.
Changes to the lists elements is not visible until you exit the loop.
Dare I ask why this is?
|
|
|
|
|
MattiasW76 wrote: Dare I ask why this is? Asking is always good, but in this case I don't know the answer. Does the same happen if you use an array instead of a list?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Using an array fixed this behaviour. Reason seems to be using the With Statement as Dave Kreskowiak said. If I take that away the list and array behaves the same.
Thank you again for helping.
|
|
|
|
|
The problem is that you're using the With statement.
With gets you a reference to an object instance. If you try to replace that object instance with a new one, like you're doing in your For loops, the With is still looking at the original object instance, NOT THE NEW ONE.
Remove the With statements and fully qualify all of your object property references and watch what happens:
Sub TestForLoop()
Dim lstRectangles As New List(Of Rectangle)
lstRectangles.Add(New Rectangle(100, 200, 1000, 2000))
lstRectangles.Add(New Rectangle(500, 700, 1500, 2000))
Dim gScale As Single = 0.1
ShowRectDimensions("Before scaling: ", lstRectangles)
Debug.WriteLine("")
For Each rect As Rectangle In lstRectangles
rect = New Rectangle(CInt(rect.Left * gScale), CInt(rect.Top * gScale),
CInt(rect.Width * gScale), CInt(rect.Height * gScale))
Debug.WriteLine("Result inside For Each Loop: {0}x{1},{2}x{3}", rect.Left, rect.Top, rect.Width, rect.Height)
Next
ShowRectDimensions("Result outside For Each Loop: ", lstRectangles)
Debug.WriteLine("")
For i As Integer = 0 To lstRectangles.Count - 1
Dim rect As Rectangle = lstRectangles(i)
lstRectangles(i) = New Rectangle(CInt(rect.Left * gScale), CInt(rect.Top * gScale),
CInt(rect.Width * gScale), CInt(rect.Height * gScale))
Debug.WriteLine("Result inside For Next Loop: {0}x{1},{2}x{3}", lstRectangles(i).Left, lstRectangles(i).Top, lstRectangles(i).Width, lstRectangles(i).Height)
Next
ShowRectDimensions("Result outside For Next Loop: ", lstRectangles)
Debug.WriteLine("")
End Sub
Private Sub ShowRectDimensions(sText As String, ByRef lstRectangles As List(Of Rectangle))
For i As Integer = 0 To lstRectangles.Count - 1
With lstRectangles(i)
Debug.WriteLine("{0}{1}x{2},{3}x{4}", sText, CStr(.Left), CStr(.Top), CStr(.Width), CStr(.Height))
End With
Next
End Sub
|
|
|
|
|
Wanted to prove this but being a Father and Husband I'm unable to control my spare time.
However, If anyone is interested I did this little code to test this:
Sub TestForLoop()
Dim lstRectangles As New List(Of Rectangle)
lstRectangles.Add(New Rectangle(100, 200, 1000, 2000))
lstRectangles.Add(New Rectangle(500, 150, 500, 200))
lstRectangles.Add(New Rectangle(500, 700, 1500, 2000))
Dim pre, n As Integer
Debug.WriteLine(vbCrLf & "Inside Loop:")
For i As Integer = 1 To lstRectangles.Count - 1
With lstRectangles(i)
lstRectangles(i) = New Rectangle(.Left + 10, .Top, .Width, .Height)
Debug.WriteLine("Rectangle " & i)
Debug.WriteLine(" 1st result, Direct Call: {0} - With-block: {1} - (Added:
10)", lstRectangles(i).Left, .Left)
n = lstRectangles(i - 1).Left / i
lstRectangles(i) = New Rectangle(.Left + n, .Top, .Width, .Height)
Debug.WriteLine("New result, Direct Call: {0} - With-block: {1} - (Added:
{2})", lstRectangles(i).Left, .Left, n)
End With
Next
Debug.WriteLine(vbCrLf & "Outside Loop:")
For i As Integer = 1 To lstRectangles.Count - 1
With lstRectangles(i)
Debug.WriteLine("Result: ({0}x{1}, {2}x{3})", .Left, .Top, .Width, .Height)
End With
Next
End Sub
This produced this result:
Inside Loop:
Rectangle 1
1st result, Direct Call: 510 - With-block: 500 - (Added: 10)
New result, Direct Call: 600 - With-block: 500 - (Added: 100)
Rectangle 2
1st result, Direct Call: 510 - With-block: 500 - (Added: 10)
New result, Direct Call: 800 - With-block: 500 - (Added: 300)
Outside Loop:
Result: (600x150, 500x200)
Result: (800x700, 1500x2000)
The result should have been 610 and 815. The added 10s disappears. This shows that the with-block reports the same value to both calculations even though there has been a change between them. However all direct calls give the updated value.
Thank you for clearing this out Dave.
|
|
|
|
|
I don't know what happened to cause this issue. I recreated the project and
the problem went away.
Hello, I'm trying to figure out how to add a custom TabPage to a TabControl.
After searching around I found this sample code of a custom TabControl which supports
my custom XmlTabPage that works as far as adding the page through the Designer but for some reason I get errors after adding the control.
In my Form:
Private Sub InitializeComponent()
Me.CustomTabControl1 = New XmlEditor.CustomTabControl
Me.XmlDataTabPage = New XmlEditor.XmlTabPage
end sub
Friend WithEvents CustomTabControl1 As XmlEditor.CustomTabControl
Friend WithEvents XmlDataTabPage As XmlEditor.XmlTabPage
'The error is that these controls are not defined. ' for the code
New XmlEditor.CustomTabControl and New XmlEditor.XmlTabPage as well
as the Friend declarations.
This code is inserted by the Designer.
These controls are part of the main project.
I can add the prefix 'Global.'XmlEditor.CustomTabControl to both controls and it
works but the next time I use the Designer, it writes the old code.
Can someone help? Below is the partial CustomTabControl code.
Thank you.
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.drawing.Design
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class CustomTabControl
Inherits System.Windows.Forms.TabControl
<System.ComponentModel.Editor(GetType(TabPageCollectionEditor), GetType(UITypeEditor))> _
Public Shadows ReadOnly Property TabPages() As TabPageCollection
Get
Return MyBase.TabPages
End Get
End Property
'UserControl overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
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.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
Public Class TabPageCollectionEditor
Inherits System.ComponentModel.Design.CollectionEditor
Public Sub New(ByVal type As Type)
MyBase.New(type)
End Sub
Protected Overrides Function CreateCollectionItemType() As System.Type
Return GetType(TabPage)
End Function
Protected Overrides Function CreateNewItemTypes() As System.Type()
Return New Type() {GetType(TabPage), GetType(XmlTabPage)}
End Function
End Class
End Class
-- modified 9-Sep-18 19:09pm.
|
|
|
|
|
Hello
In the following line of code
Dim hashedPassword = Crypto.HashPassword(password)
what would crypto be declared as, please? Most examples in tutorials refer to CryptoStream. The full code is
Public Sub CreateAccount(ByVal username As String, ByVal password As String)
Dim hashedPassword = Crypto.HashPassword(password)
CreateAccountInDatabase(username, hashedPassword)
End Sub
Private Sub CreateAccountInDatabase(username As String, hashedPassword As Object)
Throw New NotImplementedException()
End Sub
Private Sub CreateAccount(ByVal username As String, ByVal password As String, ByVal email As String)
Using connection As New OleDbConnection("connectionString")
Dim Sql As String = "INSERT INTO university (username,strEmail,hashed) VALUES (@username,@strEmail,@hashed)"
Dim cmd As New OleDbCommand(Sql)
cmd.Connection = connection
cmd.Parameters.AddWithValue("@username", username)
cmd.Parameters.AddWithValue("@strEmail", email)
Dim hashedPassword = Crypto.HashPassword(password)
cmd.Parameters.AddWithValue("@hashed", hashedPassword)
connection.Open()
cmd.ExecuteNonQuery()
End Using
End Sub
Private Sub BtnReg_Click(sender As Object, e As EventArgs) Handles BtnReg.Click
CreateAccount(username.Text, password.Text, strEmail.Text)
End Sub
Advice appreciated.
|
|
|
|
|