|
How to find the size of a structure in vb.net?
Here is my structure
Public Structure MyStruct
Public a As Byte
Public b As Integer
Public c As Double
Public d As Double
End Structure
|
|
|
|
|
Find out the size of the different data types and add them together, this will give you the max size.
The exercise is left to the student!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks Mycroft Holmes. Earlier in visual basic 6.0 we can use simply Len(structName). If the structure is too lengthy, it will be difficult to use this method..? Is there any other way ?
|
|
|
|
|
Doesn't the managed layout use the default packing/alignment as well, or is that only for P/Invoke?
The C# sizeof (the unsafe operator, not the Marshal.SizeOf method - see Dave's comment and Eric Lippert's blog) reports the size of this structure as 24, but the individual fields would only account for 21 bytes.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That depends on what you're doing with the structure.
Read this[^].
|
|
|
|
|
Hi everyone.
Built small package in vb 2005 with reportviewer. However when i converted it in vb 2010, all the forms with a reportviewer control do not work and give errors. I tried to drag and drop the control onto the form anew. It shows the action is taken place but no effect meaning the control is not placed onto the form at all.
This is my first time using vb 2010.
Thanks
|
|
|
|
|
I know your question states VS2010, but by chance are you using the express edition?
|
|
|
|
|
Thanks for replying
This is the exact error I am getting:
Error 1 Value of type 'Armory_Database.Microsoft.Reporting.WinForms.ReportViewer' cannot be converted to 'System.Windows.Forms.Control'. D:\Database Development\Armory Database Files\Report\FrmAmunition_Chart.Designer.vb 68 25 Armory Database
This error relates to a form that was created in visual studio 2005 with reportviewer control.
I am trying to open it in visual studio 2010 professional edition and I am getting the above error on all the forms with reportviewer control.
I search the web but no solution.
Thanks again for your help.
|
|
|
|
|
I was hoping that this may have been a issue with the express version as there is a simple hack to work around MS's decision to drop support for the control in the express versions[^].
I suggest you copy the error message you posted to your original post (use the edit link at the bottom of the post) so that others can see it easily. You should also show the referenced code line (68) from FrmAmunition_Chart.Designer.vb. I suspect that it is Me.Controls.Add(xxx) , but it is best not to guess.
|
|
|
|
|
Thanks for the response.
---------------------------------------------------
The error message:
Error 1 Value of type 'Armory_Database.Microsoft.Reporting.WinForms.ReportViewer' cannot be converted to 'System.Windows.Forms.Control'. D:\Database Development\Armory Database Files\Report\FrmAmunition_Chart.Designer.vb 68 25 Armory Database
-------------------------------------------
On the designer below, the error is the( Me.Controls.Add(Me.ReportViewer1).
Me.AutoScaleDimensions = New System.Drawing.SizeF(5.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.BackColor = System.Drawing.SystemColors.ActiveBorder
Me.ClientSize = New System.Drawing.Size(687, 508)
<b> Me.Controls.Add(Me.ReportViewer1)</b>
Me.Font = New System.Drawing.Font("Arial", 6.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Margin = New System.Windows.Forms.Padding(2, 3, 2, 3)
Me.Name = "FrmAmunition_Chart"
Me.Text = "Service d'Armurerie->Graphe Munitions"
CType(Me.AmmunitionTD_ViewBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.Armory_ReportAmmunition_ViewDataSet, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
----------------------------------------------------------------
I also noticed if I tried to add another Reportviewer control the form, it takes the name Reportviewer2. That means there is a Reportviewer1 already on the form but can't see it.
Thanks
|
|
|
|
|
Hello everyone;
Any feedback will be appreciated.
Thanks
|
|
|
|
|
I'm making a file downloader for game that I'm developing but I' at a loss on how to show the download speed, size, current amount downloaded, and how to execute the file once it's been downloaded from the VB app. If anyone can help me with this I'd be very grateful.
Imports System.Net
Public Class Form1
Dim WithEvents WC As New WebClient
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btndownload.Click
WC.DownloadFileAsync(New Uri("http://software-files-a.cnet.com/s/software/13/11/34/40/avast_free_antivirus_setup.exe?lop=link&ptype=3001&ontid=2239&siteId=4&edId=3&spi=47930a5e8f8651a2bc6c9fa6deeb7e68&pid=13113440&psid=10019223&token=1372207673_29dcdb8042510e0ccc215fea7880786d&fileName=avast_free_antivirus_setup.exe"), "C:\avast.exe")
End Sub
Private Sub WC_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles WC.DownloadProgressChanged
ProgressBar1.Value = e.ProgressPercentage
lblpercent.Text = ProgressBar1.Value & "%"
End Sub
End Class
|
|
|
|
|
Hi! I want to compare two datagridviews, in order to have a list of items that are common in both datagridviews, and a List of non matched itens, based on the values of an specific column - column(1) - which is found in both dgv. Also, these lists would be consolidated by the values from a column - column(2) - from the second datagridview.
An example to illustrate:
Datagridview1 Datagridview2
idProduct Item IdProduct Item IdSupplier
1 Item A 1 Item A 1
1 Item B 1 Item B 1
2 Item C 2 Item C 1
1 Item A 2
1 Item B 2
So, my desired results for the matched items would be:
IdSupplier 1 () = {Item A, Item B, Item C}; non-mathced items () = {""};
IdSupplier 2() = {Item A, Item B}; non-mathed items () = {Item C};
What I've made is a loop that filters the second datagridview, through the values from the third column, and added items that are corresponding to the first datagridview column(1) by another loop through datagridviews (Cells or Rows) and using IF statements. However, I end with a "big" list that adds all the elements, because I still do not know how to consolidate this list for each element of the third column of datagridview2.
So, from the example above, my results would be:
{Item A, Item B, Item C, Item A, Item B}
I also have tried LinQ by the following code:
For Each row As DataGridViewRow In dgv1.Rows
If Not row.IsNewRow Then
Dim row1 = row
Dim myTableSummary = (From myRow As DataGridViewRow In dgv2.Rows.Cast(Of DataGridViewRow)() Where Not myRow.IsNewRow AndAlso myRow.Cells(1).Value.ToString.Equals(row1.Cells(1).Value.ToString) Select ID1 = myRow.Cells(3).Value, _
ItemValue = myRow.Cells(1).Value Group By ID1 Into G = Group, match = Count())
Dim myArrayOfAnonymousTypes() = myTableSummary.ToArray
For Each myElement In myArrayOfAnonymousTypes
MsgBox(myElement.ID1.ToString & " - " & myElement.match.ToString)
Next
End If
Next
modified 26-Jun-13 0:37am.
|
|
|
|
|
Hi Friends,
I want to some data from Access table first save CVS File format after than it convert text format and also want that "," (Comma) replaced with "#~#" as it open
does it possible. please help me
|
|
|
|
|
Ashok Kumar9978 wrote: does it possible. Yes, if you write some code:
- Open file 1 as .csv
- Open file 2 as .txt
- Read the next record from the Access database
- Format and write to the .csv file
- Format and write to the .txt file
- Repeat until all records are processed
Use the best guess
|
|
|
|
|
|
Hi all.
I have a curious question. I know how to do this the "official" way, but I want to try to do it backwards, and it seems it should be possible. But I am new to delegates.
I have read a few articles on how to get a button to respond to mouse clicks when the main thread is super busy running some really long task. The methods always revolved around putting that task in a background thread, so that the form was not held up in any way in terms of handling events. I understand these methods fairly well right now.
But I am curious if the reverse is possible? Can the main thread be stuck in the middle of some long task, and can its form have a button that can respond to a delegate in a background task. All the button does is set/reset a public flag. If the button could respond, the flag would get valued, and that would impact what the main thread is doing.
Everything I have tried has failed, because I do not understand how to use a delegate that can support a user-interactive feature, like a button click.
I have a kludge idea that might work, but it is a bit clunky. It would involve a transparent second form on a separate thread that overlays the main thread's form, and has that button on it in the exact position where it WOULD be, if it had been on the main thread's form. So to the user, it just looks like another button on the main form. But I don't like the idea because it has a clunk factor of ten. All that work for a single button, especially since if I want to resize or move the main form, the second form has to move along with it. Just plain messy.
So it just seems that some sort of delegate approach should work to avoid all that mess.
Thanks to anyone who can offer advice on a reverse-logic idea that may be leaving a bad taste in your mouth.
|
|
|
|
|
A button has a PerformClick method - if he button is public, you could call that.
But actually that's not the way to do it. In the event handler of the button click event, you call a method to do the things you want to do on that button click. If that method is public, you could directly call it. However, if UI elements are accessed, you should check for InvokeRequired.
|
|
|
|
|
Bernhard Hiller wrote: However, if UI elements are accessed, you should check for InvokeRequired.
That's exactly where my problem is, I think. I am doing InvokeRequired, but am getting screwed up somewhere. Now, I also just got an error back at one point saying that delegates cannot handle events. I am assuming that means you can pass arguments to a control, but if you need to fire one of its events, like a button click, a delegate won't work. Not sure about that, though.
At any rate, here is my code so far. I took the guts from a demo and attempted to modify it to do the reverse of what it did originally...Run some really long task as a background thread and let the controls be free for use in the main thread. This experiment is attempting to do the opposite...Run the task in the main thread, and work the form's button via a background task. It doesn't toggle the Pause/Continue state just yet...At this point, I was just trying to get the button to respond to a simple click.
Also, the Run method at the very bottom does the Invoke, but it causes the program launch to hang during form load. I figured I might run into problems there, since I may be trying something impossible with a delegate, or I've just got everything set up wrong.
Imports System.Threading
Public Class Form1
Private Delegate Sub Pause_Continue_cmd_ClickDelegateType(_
ByVal sender As System.Object, _
ByVal e As System.EventArgs)
Private Pause_Continue_cmd_ClickDelegate As _
Pause_Continue_cmd_ClickDelegateType
Private BG_Thread As Thread
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
FormIsLoadingFlag = 1
Threading.Thread.CurrentThread.Name = "UI Thread"
ProgramLaunchFlag = 0
FormIsLoadingFlag = 0
Dim New_DelegatePauseContinueButton As New _
Delegate_Pause_Continue_Button(Me, BGThreadNumber:=1)
BG_Thread = New Thread(AddressOf New_DelegatePauseContinueButton.Run)
BG_Thread.IsBackground = True
BG_Thread.Start()
End Sub
Private Sub StartLoop_cmd_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles StartLoop_cmd.Click
Call StartLoop()
End Sub
Private Sub StartLoop()
Dim loopo As Long
Dim loopo2 As Long
For loopo = 1 To 100000000
For loopo2 = 1 To 100000000
loopo = loopo
Next loopo2
Call Pause_Continue()
Counto = Counto + 1
Me.CounterVal_echo.Text = Str(Counto)
Me.CounterVal_echo.Refresh()
Next loopo
End Sub
Public Sub Pause_Continue()
EndlessLoop:
If CountStopFlag = 0 Then Exit Sub
GoTo EndlessLoop
End Sub
Public Sub Pause_Continue_cmd_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Pause_Continue_cmd.Click
CountStopFlag = 1
End Sub
End Class
Public Class Delegate_Pause_Continue_Button
Private OwnerForm As Form1
Private Delegate Sub Pause_Continue_cmd_ClickDelegateType( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs)
Private Pause_Continue_cmd_ClickDelegate As Pause_Continue_cmd_ClickDelegateType
Private PrivateBGThreadNumber As Integer
Public Sub New(ByVal my_form As Form1, _
ByVal BGThreadNumber As Integer)
OwnerForm = my_form
PrivateBGThreadNumber = BGThreadNumber
Pause_Continue_cmd_ClickDelegate = AddressOf OwnerForm.Pause_Continue_cmd_Click
End Sub
Public Sub Run()
Try
Do
SyncLock OwnerForm
If OwnerForm.InvokeRequired() Then
Dim args() As Object = {Nothing, Nothing}
OwnerForm.Invoke(Pause_Continue_cmd_ClickDelegate)
End If
End SyncLock
Loop
Catch ex As Exception
Debug.WriteLine("Unexpected error in thread " & PrivateBGThreadNumber & vbCrLf & ex.Message)
End Try
End Sub
End Class
|
|
|
|
|
Set up an extension method:
Module Extensions
<Runtime.CompilerServices.Extension()> _
Sub SynchronisedInvoke(synchMe As ISynchronizeInvoke, action As Action)
If Not synchMe.InvokeRequired Then
action()
Else
synchMe.Invoke(action, New Object() {})
End If
End Sub
End Module
Then you can call the btnClickety method(which is fired when the button is clicked) in this manner:
btnClickety.SynchronisedInvoke(Sub() btnClickety)
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
I'll give it a try. For now, I have to get to bed...It's almost 3am! I will report back.
Update: I have some homework to do here. I am unfamiliar with action data types.
modified 25-Jun-13 20:19pm.
|
|
|
|
|
After studying this for a while, It seems that setting up an action and an extension is really just a simplification of doing an explicit delegate and attaching a method to it. So my existing code should do the same thing, then, except that I think I have the guts wrong in the Run() procedure and other places. Unless my assumptions are wrong, it seems that before I jump into Actions and Extensions, I need to understand the explicit delegate approach.
UPDATE: I am running your extensions idea, and I can get the b/g thread to run a task, but I am still not getting the button to respond, once I have the main thread caught in a long task. I was thinking that part of my problem is that I don't think the background thread is monitoring mouse behavior. When I start the program, the Form_Load sub starts the background thread, which gets the delegate going and the Run() sub is called. Even if I make the Run() procedure a continuous loop, it is going directly to the button click procedure every time, regardless of whether or not I have clicked the button. That part seems to make sense...Why would I WANT it to keep looping through the click event?! So I think I have one choice in that respect:
1. Have the Run() procedure monitor mouse behavior continuously, and when any button is clicked, check sender and only go to the Pause_Continue button click handler when it was the button in question. A monitor like that sounds like some sort of event listener. Not sure how to do that without some API functions.
UPDATE 2: After researching some more, it looks like maybe something involving WithEvents could work.
UPDATE 3: Now it looks more like AddHandler/RemoveHandler is the way to go.
modified 26-Jun-13 5:21am.
|
|
|
|
|
When I scroll down a DataGrid, then select a row in the DataGrid, then rebind the DataGrid, the DataGrid displays the rows starting with the very first row, DataGrid.Row = 0.
How do I reposition the DataGrid to display the row that was last selected?
The DataGrid is bound to a Command in the DataEnvironment.
I have tried the following code in the DataGrid.SelChange event, using the BookMarks property, where lastRow is declared as a Variant:
DataGrid1.Col = 0
lastRow = DataGrid1.Text
i = DataGrid1.Row
DataGrid1.Bookmark(i) = lastRow
When I run the code I get an error on the last line: "Run-time error '13': Type mismatch"
Any ideas? Thanks.
|
|
|
|
|
Member 9819470 wrote: DataGrid1.Bookmark(i) = lastRow I don't know what type "Bookmark(i)" is expecting, but it won't be a string.
VB6 is deprecated, and no longer supported.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi
A customer of asked us to build him a multi-language based support VB6 scraper, for which we had the need to detect UTF-8 based encoded strings to decode it later for proper displaying in application UI. It's necessary to point out that this need arises based on VB6 limitations to natively support UTF-8 in its controls, contrary to what it happens in .NET where you can tell a control that it should expect UTF-8 encoding. VB6 natively supports ISO 8859-1 and/or Windows-1252 encodings only, for which textboxes, dropdowns, listview controls, others can't be defined to natively support/expect UTF-8 as you can do in .NET considering what we just explained; so we would see weird symbols such as é, è among others, making it a whole mess at the time of displaying.
So, next function contains whole UTF-8 encoded punctuation marks and symbols from languages like Spanish, Italian, German, Portuguese, French and others, based on an excellent UTF-8 based list we got from this link - Ref. http://home.telfort.nl/~t876506/utf8tbl.html
Basically, the function compares if each and one of the listed UTF-8 encoded sentences, separated by | (pipe) are found in our passed string making a substring search first. Whether it's not found, it makes an alternative ASCII value based search to get a match. Say, a string like "Societé" (Society in english) would return FALSE through calling isUTF8("Societé") while it would return TRUE when calling isUTF8("SocietÈ") since È is the UTF-8 encoded representation of é.
Once you got it TRUE or FALSE, you can decode the string through DecodeUTF8() function for properly displaying it, a function we found somewhere else time ago and also included in this post.
[code]
Function isUTF8(ByVal ptstr As String)
Dim tUTFencoded As String
Dim tUTFencodedaux
Dim tUTFencodedASCII As String
Dim ptstrASCII As String
Dim iaux, iaux2 As Integer
Dim ffound As Boolean
ffound = False
ptstrASCII = ""
For iaux = 1 To Len(ptstr)
ptstrASCII = ptstrASCII & Asc(Mid(ptstr, iaux, 1)) & "|"
Next
tUTFencoded = "Ä|Ã…|Ç|É|Ñ|Ö|ÃŒ|á|Ã|â|ä|ã|Ã¥|ç|é|è|ê|ë|Ã|ì|î|ï|ñ|ó|ò|ô|ö|õ|ú|ù|û|ü|â€|°|¢|£|§|•|¶|ß|®|©|â„¢|´|¨|â‰|Æ|Ø|∞|±|≤|≥|Â¥|µ|∂|∑|âˆ|Ï€|∫|ª|º|Ω|æ|ø|¿|¡|¬|√|Æ’|≈|∆|«|»|…|Â|À|Ã|Õ|Å’|Å“|–|—|“|â€|‘|’|÷|â—Š|ÿ|Ÿ|â„|€|‹|›|ï¬|fl|‡|·|‚|„|‰|Â|Ú|Ã|Ë|È|Ã|ÃŽ|Ã|ÃŒ|Ó|Ô||Ã’|Ú|Û|Ù|ı|ˆ|Ëœ|¯|˘|Ë™|Ëš|¸|Ë|Ë›|ˇ" & _
"Å|Å¡|¦|²|³|¹|¼|½|¾|Ã|×|Ã|Þ|ð|ý|þ" & _
"â‰|∞|≤|≥|∂|∑|âˆ|Ï€|∫|Ω|√|≈|∆|â—Š|â„|ï¬|fl||ı|˘|Ë™|Ëš|Ë|Ë›|ˇ"
tUTFencodedaux = Split(tUTFencoded, "|")
If UBound(tUTFencodedaux) > 0 Then
iaux = 0
Do While Not ffound And Not iaux > UBound(tUTFencodedaux)
If InStr(1, ptstr, tUTFencodedaux(iaux), vbTextCompare) > 0 Then
ffound = True
End If
If Not ffound Then
'ASCII numeric search
tUTFencodedASCII = ""
For iaux2 = 1 To Len(tUTFencodedaux(iaux))
'gets ASCII numeric sequence
tUTFencodedASCII = tUTFencodedASCII & Asc(Mid(tUTFencodedaux(iaux), iaux2, 1)) & "|"
Next
'tUTFencodedASCII = Left(tUTFencodedASCII, Len(tUTFencodedASCII) - 1)
'compares numeric sequences
If InStr(1, ptstrASCII, tUTFencodedASCII) > 0 Then
ffound = True
End If
End If
iaux = iaux + 1
Loop
End If
isUTF8 = ffound
End Function
Function DecodeUTF8(s)
Dim i
Dim c
Dim n
s = s & " "
i = 1
Do While i <= Len(s)
c = Asc(Mid(s, i, 1))
If c And &H80 Then
n = 1
Do While i + n < Len(s)
If (Asc(Mid(s, i + n, 1)) And &HC0) <> &H80 Then
Exit Do
End If
n = n + 1
Loop
If n = 2 And ((c And &HE0) = &HC0) Then
c = Asc(Mid(s, i + 1, 1)) + &H40 * (c And &H1)
Else
c = 191
End If
s = Left(s, i - 1) + Chr(c) + Mid(s, i + n)
End If
i = i + 1
Loop
DecodeUTF8 = s
End Function
[/code]
Hope it helps
Regards
Diego Sendra
e-mail: contact@diegosendra.com
http://www.diegosendra.com
*Please note you have to download the function from http://www.diegosendra.com/samples/code/VB6/VB6_isUTF8.txt considering some of the UTF encoded symbols in tUTFencoded variable were lost/deleted at the time of copy/pasting the code into this thread
-- modified 24-Jun-13 20:18pm.
|
|
|
|
|