Click here to Skip to main content
       

Visual Basic

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
GeneralRe: VB.NET / APPLICATION SETTINGSmvpDave Kreskowiak29 Nov '12 - 10:36 
OK, so are these application-scope settings or user-scope settings??
 
You also don't have any code in what you posted that sets the settings with new values and persists them.

GeneralRe: VB.NET / APPLICATION SETTINGSmembermebjen29 Nov '12 - 10:57 
Dave,
 
It is 'user-scope'
 
Private Function genPoNo(ByVal user As String) As String
 
08                  Dim strNum As String = "1"
 
09                  poIncNo = My.Settings.po + 1   '----IT'S INCREMENTED HERE !
 
10                  Dim poNum As String
 
11                  Select Case user  
 
12                                 Case uFred  
 
13                                 poNum = strNum & userId + CStr(poIncNo)  
 
14                                 Return poNum  
 
15               End Select
 
16      End Function
 

Thanks MB
GeneralRe: VB.NET / APPLICATION SETTINGSmvpDave Kreskowiak29 Nov '12 - 15:50 
mebjen wrote:
  poIncNo = My.Settings.po + 1   '----IT'S INCREMENTED HERE !

 
NO, IT'S NOT! You set the value of poIncNo to the setting + 1, but you never showed where you saved that new value back into settings!

QuestionMouse Down Event and Flag settingmemberbig_col28 Nov '12 - 19:53 
Hi
 
I have a strange problem which i am not sure if it is an issue in VB
 
Public Class Form1
 
    Private moving As Boolean = False
 
    Private Sub Label2_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label2.MouseDown
        ' if the left button has been pressed

        If e.Button = Windows.Forms.MouseButtons.Left Then
            ' Set the flag to show mouse down

            moving = True
 
        End If
 
    End Sub
 
    Private Sub Label2_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label2.MouseUp
        ' The button was released, reset flag.
        moving = False
 
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label3.Text = moving
    End Sub
 
    Private Sub Form1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
 
        Dim eLocation As New System.Drawing.Point(e.X, e.Y)
 
        If moving = True Then
 

            Label1.Text = "X." & e.X & vbCrLf & "Y." & e.Y
            Label2.Location = eLocation
        End If
    End Sub
End Class
 
There is a label on the form and when you click on it is should be dragable on the form. The issue is that the flag is not been set on the mouse down event but I am not sure why or if it is the mouse move event where I test for the flag is always false. If I take the test for the flag out of the mouse move the label follows the mouse with the left mouse button down so all events seem to be working. If I declare the flag as true at start up the label also follows the mouse until the left button is pressed and released resetting the flag. I have also tried removing the flag reset in mouse up event, this actually starts to work when the left button is released.
 
Any help would be appreciated
Col
VB Express 2010
AnswerRe: Mouse Down Event and Flag settingmemberSimon_Whale28 Nov '12 - 22:46 
Have a read of this
 
Drag label anywhere[^]
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

GeneralRe: Mouse Down Event and Flag settingmemberbig_col29 Nov '12 - 2:09 
Hi
 
Yes i have Simon and i have seen a lot of examples however they all seem to stop at VB 2008, I have tried the example but the problem i have is still there. It seems that on the mouse down button it fires the mousedown event, while holding the the button and now move the mouse the mousemove event is not triggered untill the mouse button has been released. Is there any way to tell the event to end and contine looking for other events?? is this a limitation of 2010 Express version??
 
Col
GeneralRe: Mouse Down Event and Flag settingmemberSimon_Whale29 Nov '12 - 3:06 
You need to implement a mouse move event on the control not the form
 
i.e.
 
 Private Sub Control_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label2.MouseMove
        If Moving Then
            Dim ctrl As Control = CType(sender, Control)
            ' Move the control according to mouse movement
            ctrl.Left = (ctrl.Left + e.X) - cursorX
            ctrl.Top = (ctrl.Top + e.Y) - CursorY
            ' Ensure moved control stays on top of anything it is dragged on to
            ctrl.BringToFront()
        End If
    End Sub
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

AnswerRe: Mouse Down Event and Flag settingmemberbig_col29 Nov '12 - 20:19 
Thanks Simon, that was the problem the control had to have the event
 
Col
AnswerRe: Mouse Down Event and Flag settingmemberAlan N29 Nov '12 - 3:09 
Your Form1_MouseMove method handles the form's MouseMove event. Shouldn't it be attached to Label2 MouseMove?
 
Alan.
 
[EDIT, just like Simon says]
Questionvb6 to .netmemberdvdljns28 Nov '12 - 7:42 
I find I need an old vb program on win7 but got out of doing stuff like this. Despite the fact that some ways of doing things was dropped in modern windows I am guessing there is a replacement. I know send keys was considered un reliable but the problem was finding what window was the focus. Chances are the window is called something else. A good example is the program I need this for when the window is open there is no title to be seen. all my research says that vb6 is an unreliable or troublesome install on win 7. I have the source for an old vb program and have been advised to find a net replacement. And was wondering how others handled the same problems. For instance the converter by microsoft. Does it work. And how much should I expect to be converted and how much should I expect to hand code.
here is what I am talking about.
 
<pre lang = "vb">
<pre>VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   1995
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4185
   LinkTopic       =   "Form1"
   ScaleHeight     =   1995
   ScaleWidth      =   4185
   StartUpPosition =   3  'Windows Default
   Begin VB.Timer Timer1 
      Left            =   540
      Top             =   930
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
 

Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
 
Private Sub Form_Load()
    Timer1.Interval = 100
End Sub
    
Private Sub Timer1_Timer()
    Static lHwnd As Long
    Dim lCurHwnd As Long
    Dim sText As String * 255
    
    lCurHwnd = GetForegroundWindow
    If lCurHwnd = lHwnd Then Exit Sub
    lHwnd = lCurHwnd
    If lHwnd <> hwnd Then
        Caption = "ActiveWidow: " & Left$(sText, GetWindowText(lHwnd, ByVal sText, 255))
        Debug.Print Caption
    Else
        Caption = "ActiveWindow: Form1"
    End If
End Sub
Is there an easy way to do this on win 7?
AnswerRe: vb6 to .netmemberZaf Khan28 Nov '12 - 16:58 
Is this what you mean?
 
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Timer1.Interval = 250
End Sub
 
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Static lHwnd As Long
    Dim lCurHwnd As Long
    Dim sText As String
 
    sText = ""
    lCurHwnd = GetForegroundWindow
    If lCurHwnd = lHwnd Then Exit Sub
    GetWindowText(lHwnd, sText, 255)
    lHwnd = lCurHwnd
    If lHwnd <> Me.Handle Then
        Me.Text = "ActiveWindow: " & Microsoft.VisualBasic.Left(sText, 255)
        Debug.Print(Me.Text)
    Else
        Me.Text = "ActiveWindow: Form1"
    End If
End Sub

GeneralRe: vb6 to .netmemberdvdljns1 Dec '12 - 5:47 
thank you for your answer.if I don't know the .net I am probally going to get into trouble. Yes that looks like what I am trying to work with. Though the coding there looks a lot better then what I came up with. Let me explain the problems I am having and maybe as coders you can tell me how I should handle it. I have a program I need to find the active window on. one of the problems I think is the program takes over my comp. and by that I mean I can not easly run any other program while this program is running. but a lot of my input is repetitive meaning I have to hit the same set of keys over and over.
sometimes for as long as an hour. I have found some stuff will run as long as it is in the background.My idea was a simple script to find the active window and handle then senkeys to send the keystrokes to it. But heres my glitch. I can not get the script to stay open long enough to read the info and everyone tells me I should never use sendkeys for this. the only advise I get is find another way besides send keys.but no search or no one has sugested another way. I tried stuff like autoit but failed on all attempts. Is there a better way? or maybe a progam I could use?
GeneralRe: vb6 to .netmemberZaf Khan1 Dec '12 - 8:00 
I think if you simply want to find the active window, then you should should run the script as a function (within a common module) rather than in a timer (in a form) or at the very least disable the timer once you have found the active window.
 
The sample code you provided lives in the TIMER's event routine within the FORM.
This would also mean if you have several forms then they are all running concurrently.
And this is why your system is becoming unresponsive?
 
For what you want to do, I dont think the sendkeys is the problem, its probably the timer which runs every so often... (100 milliseconds i think you had it at).
 
If everyone tells you you shouldn't use sendkeys to do what you want, then more than likely they are right! After all so many people cannot be wrong?
Maybe you could use API functions to attain the results you want?
Im not sure but it cannot be too difficult for you to find the answer in the documentation on MSDN.
 
I have seen several posts on this websites forum which deal with finding the active window.
Maybe surfing through those threads/posts would give you a better resolution to your issue.
AnswerRe: vb6 to .netmvpDave Kreskowiak28 Nov '12 - 18:04 
The VB6 code migration wizard no longer exists in Visual Studio 2010 and above. If you've got VB6 code to convert, you'll either need to use Visual Studio 2008 to do a conversion, the quality of which depends entirely on your VB6 code. The more PInvoke stuff you have in it, they worse the conversion will be.
 
Keep in mind that the conversion utility will not rewrite your code to what you can do by hand today under .NET. It will convert the project so that it has a decent chance of at least compiling. VB6 did so many things poorly that it's sometimes just impossible for it to figure out what you were doing and rewrite appropriately.

QuestionDeleting a datarow, creating a query to find the row. - ANSWERED, Thank yo [modified]memberJRHibner27 Nov '12 - 23:30 
Hello,
 
I'm using:
Microsoft Visual Basic 2008, Professional Edition
 
I've run into a problem I can't figure out. I'm using VB 2008. I found the following sample code and was attempting to use it but am not understanding how to setup the query, I bolded it below.
 
I understand I need to go in and set up my own customer query in my database in order to use it like the example below.
Q) Do I setup the query on my table adapter or on the original table in the database (Maybe even some good info on how to setup these queries)?
 
Q)If I'm understanding this, once I setup the query correctly I should just have to put in a variable and it fill find all row(s) with that parameter that I can delete?
 
Q) When using the @XXXX in the query, do I have to then use that as my variable to pass the data I'm looking for or can I use and variable?
 
' Locate the row to delete.
Dim oldRegionRow As NorthwindDataSet.RegionRow
oldRegionRow = NorthwindDataSet._Region.FindByRegionID(5)
 
' Delete the row from the dataset
oldRegionRow.Delete()
 
' Delete the row from the database
Me.RegionTableAdapter.Update(Me.NorthwindDataSet._Region)
 
I was able to setup the following query on my database but per the example, I'm not sure I did it correctly:
 
SELECT        Gene, FindMethod, TDiscovery, TReplicate, AA_A, AA_T, AA_G, AA_C, ImageFileName, Description, SpxReplicationItem, IconFileName, Complete, Image, Icon, Type,
                         UniqueID, Chromosome, Rarity, ParentGene, Name
FROM            PlazimorphGenes
WHERE        (Gene = @genename)
 
I then tried using it as this:
 
tRow = PlazimorphDBDataSet.PlazimorphGenes.FillByGene(genename) 
 
and got an error that it is not a member of the database.
 
Thank you for all the help! I've been searching this forum and the web in general and have found the best help here!

modified 1 Dec '12 - 15:44.

AnswerRe: Deleting a datarow, creating a query to find the row.memberAndy_L_J28 Nov '12 - 22:30 
Have you got a link to the code you are trying?
 
I suspect that you require a Stored Procedure on the Database:
  USE BDNAME
GO
 
CREATE PROCEDURE SelectByGeneName(
  @GeneName VarChar(100)
)
AS
BEGIN
  SET NOCOUNT ON;
 
  SELECT Gene, FindMethod, TDiscovery, TReplicate, AA_A, AA_T, AA_G, AA_C, ImageFileName, Description, SpxReplicationItem, IconFileName, Complete, Image, Icon, Type,
           UniqueID, Chromosome, Rarity, ParentGene, Name
  FROM PlazimorphGenes
    WHERE Gene = @genename
 
  RETURN;
 
END
GO
 
I dont use the automatic binding etc...so I would retreive the data like this:
Public Function GetByGeneName(name as String) As DataTable
  Dim cn as New SqlConnection(ConnStr) ' Your connection string
  Dim cmd as New SqlCommand
  Dim dt as New DataTable("PlazimorphGenes")
  Try
    cn.Open()
    With cmd
      .Connection = cn
      .CommandType = CommandType.StoredProcedure
      .CommandText = "SelectByGeneName"             ' The StoredProcedure Name 
      .Parameters.AddWithValue("@GeneName", name)   ' Set the input parameter
      Dim da as New SqlDataAdapter(cmd)
      da.Fill(dt)                                   ' This fills your DataTable
    End With
Catch ex as Exception
  ...
Finally
  If cn.State <> ConnectionState.Closed Then cn.Close()
End Try
 
Return dt
 
End Function
I don't speak Idiot - please talk slowly and clearly
 
"I have sexdaily. I mean dyslexia. Fcuk!"
 
Driven to the arms of Heineken by the wife

GeneralRe: Deleting a datarow, creating a query to find the row.memberJRHibner1 Dec '12 - 7:21 
I was attempting to use the sample code above like this:
 
Dim tRow As PlazimorphDBDataSet.PlazimorphGenesRow
Dim genename As String
genename = MTBGeneLabel.Text.ToString()
tRow = Me.PlazimorphGenesTA.FillByGene(Me.PlazimorphDBDataSet.PlazimorphGenes, genename)
tRow.Delete()
Me.PlazimorphGenesTA.Update(Me.PlazimorphDBDataSet.PlazimorphGenes)
 

I did go into the database designer and create the specific query on the table. It looks SELECT code section you posted above.
 
The error I'm getting is specific to this line:
 
tRow = Me.PlazimorphGenesTA.FillByGene(Me.PlazimorphDBDataSet.PlazimorphGenes, genename)
 
I'm getting
"Value of type 'Integer' cannot be converted to 'PlazimorphAdmin.PlazimorphDBDataSet.PlazimorphGenesRow'"
 
I thought Visual Studio would automatically add the stored procedure. Maybe I need to add it as you suggest.
 
If I change the line to this:
 
tRow = Me.PlazimorphGenesTA.FillByGene(genename)
 
I get the following two errors:
 
"Argument not specified for parameter 'genename' of 'Public Overrideable Overloads Function FillByGene(dataTable as PlazimorphDBDataSet.PlazimorphGenesDataTable, genename as String) As Integer'."
 
and
 
"Value of type 'String' cannot be converted to 'PlazimorphAdmin.PlazimorphDBDataSet.PlazimorphGenesDataTable'."
 
And If I use this version:
 
tRow = Me.PlazimorphGenesTA.FillByGene(tPlazimorphGenes, genename)
 
I get
"Value of type 'Integer' cannot be converted to 'PlazimorphAdmin.PlazimorphDBDataSet.PlazimorphGenesRow'"
 
The query I have attached to the table is this:
 
SELECT Gene, FindMethod, TDiscovery, TReplicate, AA_A, AA_T, AA_G, AA_C, ImageFileName, Description, SpxReplicationItem, IconFileName, Complete, Image, Icon, Type,
UniqueID, Chromosome, Rarity, ParentGene, Name
FROM PlazimorphGenes
WHERE (Gene = @genename)
 

I have a solid background in visual basic programming but haven't work this much with a database.
GeneralRe: Deleting a datarow, creating a query to find the row.memberAndy_L_J1 Dec '12 - 20:27 
OK, are you generating the DataSet from the Visual Studio Wizard?
 
This exposes you to the evils of the BindingSource, TableAdapter, and TableAdapterManager classes. (I and many others here avoid them like the plague).
 
This may be a usefull article: A Detailed Data Binding Tutorial (CP)[^]
 
Rolling your own database access is not so hard:
...
Dim cn As New SqlConnection("myConnectionStringHere")
Dim cmd As New SqlCommand()
Try
  cn.Open()
  With cmd
    .Connection = cn
    .CommandType = CommandType.Text
    .CommandTExt = "your SELECT query here"
    .Parameters.AddWithValue("@genename", yourGeneNameVariable)
    Dim dt As New DataTable("PlazimorphGenes")
    Dim da As New SqlDataAdapter(cmd)
    da.Fill(dt)
 
    plazimorphGenesDataGrid.DataSource = dt
 
  End With
...
 
you can then look after the delete query yourself too
...
Dim dr as DataRow = tRow(0)
Dim queryString as String = "DELETE PlazimorphGenes WHERE Id = @Id"  ' Correct synatax escapes me
Dim cn As New SqlConnection("yourConectionString")
Dim cmd As New SqlCommand
Try
  cn.Open()
  With cmd
    .Connection = cn
    .CommandType = CommandType.Text
    .CommandText = queryString
    .Parameters.AddWithValue("@Id", CInt(dr("Id")))
    .ExecuteNonQuery()
  End With
 
  UpdateDataGrid(...)
 
I don't speak Idiot - please talk slowly and clearly
 
"I have sexdaily. I mean dyslexia. Fcuk!"
 
Driven to the arms of Heineken by the wife

GeneralRe: Deleting a datarow, creating a query to find the row.memberJRHibner9 Dec '12 - 14:55 
Thank you for the link! Yes, I've used the data wizard. It's been a few years working on such a big database project as a 'hobby project'. Most of the tutorials and examples use it.
 
I've been able to create a DELETE function on the tables and its working, also a INSERT on.
 
The next step I've having issue with is filling a combo box with a query. I've added the query to the table but can't get it/figure our how to apply it to filtering data to the combo box. I also tried using the 'Filter' on the Binding source but it doesn't seem to work.
QuestionModified Registry Keymemberalirezamansoori27 Nov '12 - 18:52 
hi
Wanted with VB.Net Last Date modified Registry key
To do this I need to use the RegQueryInfoKey API
AnswerRe: Modified Registry KeymvpRichard MacCutchan28 Nov '12 - 0:02 
alirezamansoori wrote:
I need to use the RegQueryInfoKey API
Very true; you also need to use the documentation[^].
One of these days I'm going to think of a really clever signature.

GeneralRe: Modified Registry Keymemberalirezamansoori28 Nov '12 - 0:39 
RegistryKey Class does not have the ability to do my job
GeneralRe: Modified Registry KeymvpRichard MacCutchan28 Nov '12 - 1:15 
Then you probably need to use P/Invoke[^] to get access to the Win32 function.
One of these days I'm going to think of a really clever signature.

QuestionLooking for idea for learning bookmemberNaZReD24 Nov '12 - 9:08 
Hi,
 
i want to learn more about VB & how i can make a program that will allow me to
Add Quotations
make calulation from user inputs,
Cross-ref this information agaisnt a M$ database,
then export a quotation into a pdf, and also export data into M$ Database to create new jobs,
and finally i would like to create a Order acknowledgement from all the information to send to customers & export into Sage.
 

im hoping there is a magical book that can teach me all these steps Smile | :)
 
and hoping i can buy it from amazon Smile | :)
 
and hoping you guys and gals may know the perfect book! Wink | ;-)
Blush | :O
 

we have been using a system at work at for many years now, which i did create but it is very disjointed,
quotations = made in Excel manual input and searchs
Job = created in Access manual input from quotations
Order acknowledgements = made in sage - another manual repeated job.
 
overal a job is re-entered 3 to 4 time repeated. when new & 2 times when existing and its a re-order.
 
so im hoping i can strimeline all this down Wink | ;-)
AnswerRe: Looking for idea for learning bookmemberEddy Vluggen27 Nov '12 - 12:58 
Books aren't written to accommodate ones business-requirements. There are a bunch of video's and how-to's on MSDN, that'd might be a useful introduction into the specific topics you request. I'd recommend "Head on C#", but it's not about VB and not about Access.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 17 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid