Converting A "Handles" Statement To C#?
Apr 13, 2010converting a VB.NET handles statement to C#. This is the VB
View 3 Repliesconverting a VB.NET handles statement to C#. This is the VB
View 3 RepliesI have this piece of code which is calling some functions in a web service. however the original was written in VB and when I have converted it it gives me an error in my c# stating that 'The name Information does not exist in the current context' I have checked the VB and it win there either!
[Code]...
Can some one convert this statement from c# to VB.net for me?
double pressure = (int)(((usbRecord[8]) & (byte)(0x0f)) << 8) + (int)(usbRecord[7]);
In a vb script program, I have the following code objCommand.Properties("Page Size") = 9999..I have converted most of the vb code over, but this statement gives me a "Property Item is ReadOnly" error. How can I rewrite this line to work in vb.net?
View 2 Repliesi have to convert a visual basic 6 program to the visual basic 2008. i used the wizard that is provided to upgrade but that just doesn't work. It comes up with many errors. most of them are End of statement expected and Number of indexes exceeds the number of dimensions of the indexed array. I really don't know what to do with them and i have to fix them in order for it to run.
View 18 RepliesI am converting C# program to VB. I heard that "Yield" statement is ready from Visual Studio 2010 SP1.
[URL]
I updated my developing environment to Visual Studio 2010 SP1. However IDE still displays error to the following code saying that "yield" is not delclared.
Public Class WeakCollection(Of T)
Implements IEnumerable(Of T)...
ReadOnly innerList As List(Of WeakReference) = New List(Of WeakReference)()
[CODE]...
How can I use "Yield" statement in VB?
my goal is to
1.Take an file(exe,dll,etc)
2.Convert it into hex
3.place that hex values in a stack
4.Execute the values inside the stack to its original form(i.e. take the elements out of stack and then convert it to a compile format)
Imports System.IO
Sub Main()
Dim fileName As String = "ABC.exe"
[code]....
Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemClick
End Sub
In VB.net, we have the Handles keyword, I'm wondering if C# has anything comparable. Or do you have to manually wire all the methods to each control's event (in ASP.NET especially)?
The short program below runs just fine when it is the only item on a form. However, when I put it into the ItemInsertTemplate of a ListView control, I get the following message:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types
Line 30: Protected Sub btnDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDate.Click
The error message identifies Line 30 as the problem.I get the same message for Sub clnEvent_SelectionChanged How do I correct this?
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="clnControl.aspx.vb" Inherits="clnControl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
[code].....
I'm migrating some code from VB.NET to C# (3.5).I find structurs like:
Public Event DataLoaded(ByVal sender As Object, ByVal e As EventArgs)
Protected Sub Mag_Button_Load_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Mag_Button_Load.Click
[..]
[code]....
What is the most streight-forward to translate such behavour in C#?
I am making a webbrowser and I am now trying to make the XButton1 go back. I have that working but I can not get it to work when the WebBrowser is active. My cursor has to be over the form (Me.MouseDown) I can't use WebBrowser.MouseDown because there is no browser until the application is opened. It is a a tabbed browser. The first browser is created like this.
Try
Dim Tab As New System.Windows.Forms.TabPage
Dim Browser As New System.Windows.Forms.WebBrowser
Browser.Dock = System.Windows.Forms.DockStyle.Fill
[code]....
Using Visual Studio 2008 I am trying to create two subs using the same handles:
Private Sub checkwin(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click
[Code].....
As these both use the same handles one sub overwrites the other...... Both subs contain If statements. Do I need to create two different handles... and how do I do this so that the handles use the same buttons?
I have a simple program that was written to access data from multiple access tables. I have everything running perfectly however I did encounter an error with the exit button. I have removed the control from the window and replaced it with a exit button on the form. However I am getting an error reading: "Handles clause requires a WithEvents variable defined in the containing type or one of its base types."I am a little confused because I have this exact same line of code in two other programs and it runs fine. I have read up on this and I know that I need a line of code that reads something like " Friend WithEvents Button1 AsSystem.Windows.Forms.Button" However I am not real clear on what friend means here and where exactly the With Events goes in my code?
Code for exit button
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click'The problem is with this line of code'
[code]....
Is there a way to simply the Handles statement? What if i want this sub to handle 20 textboxes do I have to list each textbox there? I already have a loop in my script so i can cycle through my textboxes ("TextBox" & i.text). is there anyway to use a variable or a function after handles to get all the names of the text boxes?
Private Sub textChange(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress,TextBox2.KeyPress, TextBox3.KeyPress, TextBox4.KeyPress, TextBox5.KeyPress
(How to get The Handles Of process?)
View 2 RepliesIf I have two instances of the same form open, and one is on top of the other and I want to go to the one on the bottom, I have to click the form to bring it to the front.. I changed this so that if i click the panel(which represents the forms background) I have it bring it to the front.. But now I am having the issue where I click a control in that panel it wont bring it to the front.. So i know how to do this.. I can make a procedure handle all the controls onclick events by typing each controls name.click event
View 33 RepliesWhat i want to do is grab the handle of a webbroswer control and only read the co-ordinates within those bounds. I have successfully manager to do this but the problem i am now having is moving the mouse to those co-ordinates, for some reason after getting the handle and moving the mouse:
Windows.Forms.Cursor.Position = WebBrowser1.PointToClient(New Point(x, y))
It still reads full screen co-ordinates.
See
Public Class Form1
Dim sql As String
Dim conn As New OleDb.OleDbConnection
Dim da As New OleDb.OleDbDataAdapter
[CODE]...
The problem, The INSERT statement works fine in the form load but not in the button click event?
sub I use on all forms in my app I would like to put in one central place (of course right). in vb.net I put this sub in a module it has a "Handles tabcontrol1.Drawitem" - I get an error saying handle requires with events variable defined in containing type or one of its base types.also when I refer to tabcontrol1 in a module it wants to know which form.. Can I use sender to define current calling form?
sub
Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
Dim g As Graphics = e.Graphics
Dim tp As TabPage = sender.TabControl1.TabPages(e.Index)
Dim br As Brush
[code]....
I've been using Shell() to launch an application, and Process.GetProcessById() to get the handle to that window, but I think I'm running into problems when passing the handle around to various functions. What is the best way to declare and pass windows handles so that they will be usable? After viewing the debug, it seems the Shell() and Process.GetProcessById() work fine. After I pass the handle off to the functions I need to use them in, the program starts spitting out garbage, and not doing what I want it to do. Short version of the proces
[Code]....
here is what i want to do:
Private Sub UpdateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
MyUpdate.CheckUpdate("version.txt")
[code].....
I have a problem that i can't understand. My Handle Click event does not work !Specifically i have a table (1 row 2 columns). In the first cell i have a datagrid and some text boxes and a button. My button does not work ! In the other cell i have text boxes as well and a button, here, at the 2nd cell the button works! What's the problem then
View 9 RepliesJust about every day as I build my app and run/test it, I click on a control (button, grid, anything) and nothing happens.I double-click the control in design mode, and it's like clicking on a new control, no code is there.It turns out that the control loses the part of the line of code.[code]This has happened so often that I know I'm not deleting it accidentally.
View 8 RepliesCheck process handle count:In Task manager, View, Select columns, mark Handle Count to the view.(The process when loaded has about 333 handles)
Operation:The new thread is set equal to an existing thread, then the existing thread is started and aborted. How does one restore the old handle count? Why do the handles increase by a random number and do not revert?
How can Idisposable/CloseHandle/or GC.collect, Finalize() work in this situation? I'm trying to return the handles to their original count, 333, when I start a new thread it adds 4,5, or 6 handles per new thread(even if the thread is aborted and set to nothing).
[Code]...
I am trying to use multiple handles to trigger one event but I need each handle to effect the event differently. I feel like this should be simple. I want to use a Select Case to select the alteration but I can not figure out how to identify the handle used and convey that to the Select Case.
Private Sub Event(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click, Button2.Click
Select Case handles[code].....
get a listing of all current open windows, with their captions and have the option to close these windows via code.
View 22 RepliesIs WithEvents & Handles usage preferable to RemoveHandler & AddHandler?
From Memory point of view (remove an added handler after utilization, etc.)
I have searched far and wide and have not been able to find a solution to my problem.I have a typical situation where a process is gradually eating up memory. The process eventually throws an OutofMemory Exception. This problem has been dealt with in the past by just building a special machine that has greater memory.
This process bombs on only one of our clients which has around 450,000 records. We iterate through the collection of accounts and build a class object that is then passed into the xml serializer. This object has several properties and methods that would not all be populated at the same time. These objects are populated based on the information in each account record.
I've checked on the way we call the contructor for the XML Serializer and it is in the format that would store the xml assembly and not create new ones each time. So, I do not believe there is a memory leak due to the creation of the dynamic assemblies.How we call the serializer: Dim k1Serializer As New XmlSerializer(GetType(ClassObject))
My questions are:When serializing a large object, does the serializer look at every possible serializable object or just the ones that are populated by your object?
Could the serialization of this large class object be causing an issue?I noticed when we pass in the serialized object, it's not automatically written out to the file specified. It takes a few seconds to, I guess, serialize the object and then write it out. Could the fact that we are iterating over so many records, so quickly, that the serializer is not having enough time to write out to the file and then release the memory?
I was convinced that If <expression> Then <statement [:statement]> Else [statements] in concrete form of If a = b Then SayHello() Else SayBye() End has sense. I read article on msdn on If-then-else, but I forgot why I was reading, so I concluded, that snippet above means this
If a = b Then HelloIsSaid : IsNotEnded Else ByeIsSaid : IsEnded But I have tested it now, and I see, that Else without statement is nothing more than decoration. It would be pretty good if it had function I described. Do you think its good request? Or do you know any circumstance where this Else has some function?
y friend and I are re-learning Visual Basic, and we are stumped on this bit of code.
For intAsterisks As Integer = 0 To intLine - 1
lblAsterisks.Text = lblAsterisks.Text + "*"
Next