Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all 27409 articles
Browse latest View live

VS 2015 Serial Communication Question

$
0
0
Hi Everyone

First sorry if this has previously been posted. But I'm not sure how to explain it myself

I've attached a picture of what I am wanting to do. If anyone can explain how I could find 16 and remove it and subtract 64 from the next byte I would be very thankful or even point me in a direction where I could source information about this such thing.

Thanks for reading

Name:  Scan0001.jpg
Views: 32
Size:  18.9 KB
Attached Images
 

get a running assembly as assembly

$
0
0
I am down to one error in my current application trying to raise the .net level to run on 7 that I cannot figure out. This one is a little over my head. It is trying to get a running assembly but it is not casting it as anything. Any help would be great.
Code:

If Globalr.currentDb.sorts(i).ocrActive Then
 num = Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly.GetModules(0)).ToInt32
If (CInt(-(Globalr.OCRObject.OCRSetParameters(0, 0, pathname, num) > False)) = 0) Then
Interaction.MsgBox("OCRSetParameters failed", MsgBoxStyle.Exclamation, Nothing)

Comparing value in label to value in database

$
0
0
I am creating a multiple choice quiz but I am not sure how to check if the answer selected is the correct one.
I have

Code:

If radAnswer1.Checked = True Then
 
        End If

But do not know what to put after the "then". I am trying to compare the value in a label called lblAnswer1 with a value in my database called Correct Answer.
The value in lblAnswer1 is linked to the Answer 1 field in my database.
I will do the same for the other 3 possible answers.

Any help would be much appreciated.

VS 2015 Detect if Drawing is Past the Edge of Screen

$
0
0
I have a string graphics drawing. I have centered it on the screen, but can't find a way to detect if it has gone past its edge.

Here's what I'm trying to achieve with the detection:

Code:

Dim gr As Graphics = Me.CreateGraphics
        Dim mybrush As Brush
            mybrush = New SolidBrush(Color.White)
            Dim sf As New StringFormat 'centre string
            sf.LineAlignment = StringAlignment.Center
            sf.Alignment = StringAlignment.Center
            gr.TranslateTransform(Me.Width / 2, Me.Height / 2)
dim counter = 0
Do While Drawing is in screen 'obviously what it want to do, not actual code
counter += 1
            gr.DrawString(todrawstring, New Font("Arial", counter), mybrush, New Point(0, 0), sf) 'draw string as big as possible
Loop

The solution must allow space for a margin between the edge of the text and the edge of the screen.

VS 2010 Interrogating an Exchange Mailbox

$
0
0
Hi

I've recently build a Windows Service which takes information from a database and turns it into an outgoing email. It then attempts to transmit that email and (depending on the response that comes back from the outgoing email server) either marks the "email" as having been sent or flags that it failed (perhaps because of a timeout error) and retries it later in the day.

I've been asked to find out whether or not it's possible to identify those outgoing emails that resulted in a "bounce-back" being received into the mailbox from which the email was sent. I need to be able to differentiate between bounce-backs that were received because the email address doesn't exist, as opposed to bounce-backs that were received because the recipient mailbox was full.

Can someone point me in the right direction for this? Initially I plan to use my own mailbox as a test.

Thanks in advance.

VS 2008 How to auto populate a MS Access date field with today's date

$
0
0
Hi all,

I'm building small app for school. It's designed to help a plumber to generate quotes for building work. I wanted to set it up so that whenever Pete the Plumber creates a new quote, the day's date is entered into a date field. Another date, 30 days later is the date the quote will expire. See below:

Name:  kjxQvkj.jpg
Views: 10
Size:  26.8 KB

But as you can see the date does not get saved onto the Access table. However, if I manually select a date other than the default one, it works fine. Again, see image below

Name:  BycfrVS.jpg
Views: 12
Size:  27.7 KB

Here's my code, I just set the date in the form load sub.

Code:

Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' Adds today's date to the quote date as a defalut
        QuoteDateDateTimePicker.Value = Date.Today

        ' Creates automatic expiry date for quote in 30 days
        QuoteExpiryDateTimePicker.Value = Date.Today.AddDays(30D)

I know this isn't the best way the whole project could have been set up, but... please help!
Attached Images
  

making heads or tails of Class not registered (Exception from HRESULT: 0x80040154 (RE

$
0
0
So a class is not reigstered. I think I understand that, but it really does not make sense I cannot open the form. Here are the imports
4 local dlls that are common to the project like firebird and such
and then
Imports Microsoft.VisualBasic
Imports Microsoft.VisualBasic.CompilerServices
Imports System
Imports System.ComponentModel
Imports System.Data
Imports System.Diagnostics
Imports System.Drawing
Imports System.IO
Imports System.Net
Imports System.Resources
Imports System.Runtime.CompilerServices
Imports System.Threading
Imports System.Windows.Forms

nothing too crazy and nothing that should not be registered. I can find them all in the registry so, I am really confused. The only thing even weird about this project is one of the classes that this class calls would require it to be active, but it even does the same if you try to run it. It is definitely set on x86, so I am stuck. here is the stack. If anyone know who to pull more information from the error let me know. I know how to do it in c#, but no idea in vb.
at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
at System.Windows.Forms.AxHost.CreateInstance()
at System.Windows.Forms.AxHost.GetOcxCreate()
at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
at System.Windows.Forms.AxHost.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at System.Windows.Forms.Form.ControlCollection.Add(Control value)
at System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.Add(Control c)

im lost:(Name:  Capture.PNG
Views: 3
Size:  40.8 KB

I have also attached the stack from trying to run it. I cannot even open the form in the editor.
Attached Images
 

Security in vb.net project

$
0
0
Hi everyone. Am new into this forum. Am looking for some topics to work on as a project on security. Anyone who can help me with one or two? Will really appreciate it.

Thanks

[RESOLVED *#$^@!!!] Vexing DB Update Issue

$
0
0
This will take a bit of explaining. I'm getting an error with this message:

Quote:

You cannot add or change a record because a related record is required in table 'STRM_Survey'.
That appears pretty straightforward...until we get to the details. The program populates Access databases for remote use based on data in a SQL Server database. As part of this operation, there are these lines of code (which are all that I think are probably relevant):

Code:

cmd.CommandText = mSGSATester.GetSelectClause("STRM_Survey") & ",UploadDate FROM STRM_Survey"
cb = New OleDb.OleDbCommandBuilder(da)
da.Update(mDS, "STRM_Survey")

cmd.CommandText = mSGSATester.GetSelectClause("STRM_Survey_Waypoints") & " FROM STRM_Survey_Waypoints"
cb = New OleDb.OleDbCommandBuilder(da)
da.Update(mDS, "STRM_Survey_Waypoints")

As you can see, the code updates table STRM_Survey first, then updates table STRM_Survey_Waypoints, which has a foreign key relationship to STRM_Survey on one field (SurveyID). Most of the time, this code is sufficient. The program has worked well for some time and continues to work well. However, I recently found that there were some other pick list tables in the target Access database that were slightly stale under some circumstances. The program was written to detect this condition and update those pick list tables if necessary.

If the pick lists needed to be updated, the first part of the posted code would fail with a similar message to the one shown, except that it would say that a related record was needed in one of the pick lists. When that happens, I update the pick lists and run this code a second time. Note that neither STRM_Survey nor STRM_Survey_Waypoints are pick list tables.

So, I processed some data where the pick lists didn't need to be updated and it all worked perfectly. However, I really wanted to test out the code to update the pick lists, so I deliberately broke one of those pick lists. The code failed (as it should) on the update of STRM_Survey, which launched the code to update the pick lists. After the pick lists had been updated, the posted code ran a second time. That second time through, the update to STRM_Survey did not fail and all 161 records were written, which is as it should be. This shows that the pick lists had, indeed, been updated.

The code then failed on the update of the waypoints with the message shown. Keep in mind that the waypoint table doesn't have any relationships with any table other than STRM_Survey, and STRM_Survey did update correctly, so the records were there. Furthermore, if the pick lists didn't have to be updated, then the waypoint table updated without issue.

That had me baffled, so I decided to see which waypoint record didn't have a matching survey record. To do that, I wrote this silly little method:

Code:

Private Sub TrialEvaluation()
        For Each drW As DataRow In mDS.Tables("STRM_Survey_Waypoints").Rows
            Dim drs = mDS.Tables("STRM_Survey").Select("SurveyID = '" & drW("SurveyID").ToString & "'").FirstOrDefault
            If drs Is Nothing Then
                Dim x As Integer = 5
            End If
        Next
    End Sub

All that does is goes through each record in the waypoints table and looks for a related record in the survey table. If no related record is found, then drs will be Nothing and the If will evaluate to true. The line in the if is just there so I can put a breakpoint on it. The breakpoint is never hit, which means that every record in the waypoints table does, in fact, have a related record in the survey table. That can be confirmed by the fact that, if the pick lists don't need to be updated, the waypoints update without issue, which shows that there really is a related survey for each waypoint.

Can anybody suggest what is happening, or what more I can do to investigate this situation?

Calling vb from C# in same solution

$
0
0
I thought this should be simple ;)
I have a big web site VS2013 VB ASPX solution.
Everything has been in VB and it has been easy e.g. to call from code-behind (x.aspx.vb) to App_Code classes, or between App_Code classes.

Now I was given a big chunk of C# source code that I should use, and I wouldn't like to spend hours translate all those lines to VB (and I am not so good at C#). And anyway, I thought it should be simple to call in between, since they are sibling languages in .Net.

So, both the C# and VB source is in the same solution.

I realized that I had to separate the C# and the VB source to different folders, and put the tag codeSubDirectories in web.config, otherwise the compiler yelled.
So, the structure in the Solution Explorer is now:
Solution WebSiteTstComfCallBack
WebSiteTstComfCallBack
App_Code folder
CsCode folder
Service.cs
VbTestComfact2.vb
...
default.aspx
default.aspx.vb

This compiles and runs nicely if I don't try to call from C# to VB - from e.g. default.aspx.vb I can easily call a Sub in VbTestComfact2.vb, intellisense finds it immediately.

But inside Service.cs I cannot do new or using on the VbTestComfact2 class, and intellisense in C# does not find it.

I've tried adding a Namespace x in VbTestComfact2 but C# intellisense does not find that either. Also tried Namespace Global.x, same problem.

So, what do I need to declare more?

VS 2013 suppress KeyDown "Shift", and instead make Key capitalized?

$
0
0
hi guys, im new to this forum, and im also really new to vb.net..

i was wondering how i would make my ListBox input a capitalized or undercased key, depending if Shift is held down or not..

Code:

    Private Sub frmMain_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
        If (IsOn) Then
            Dim Key As String = (ChrW(e.KeyValue.ToString))
            If (Not e.KeyCode = Keys.Shift) Then
                lstKey.Items.Add(LCase(Key)) 'Uppercase
            Else
                lstKey.Items.Add(Key) 'Lowercase
            End If
        End If
    End Sub

it should work, but when i actually press Shift, it enters the Shift KeyCode into the ListBox.. how would i stop it from doing that??

appreciated! :)

VS 2013 Dropping Wi-Fi connection VB.NET 2013

$
0
0
Hello!

Wrote a simple data retrieval/update app in VB.NET 2013. It is running on a Surface 3 with Windows 10. Data access is wireless.

If WiFi connection is dropped or falls down below a certain threshold the app freezes up, and locks the entire Surface up. Sometimes it releases resources but sometimes it requires a full reboot to fix this.

Is there any way to trap this, and in general what is a proper way to handle this situation?

Merge Two Text Files With No Duplication...

$
0
0
I have to merge two application config/settings files like the following...

File one is a configuration file already deployed on a users system and looks something like this, for example...

;TestingBS
;company.testing=BS


They commented out the company.testing value to suit their needs.

File two looks something like this. This is the file that will be included in an upgrade. Anything that matches in any way to File one should be left alone...

;TestingBS
company.testing=BS

;New Value
value.new=1



You'll notice that the first value in this file is not commented out, but that is not to be translated to the output file as the users current configuration is to be maintained. Also, any new values should be pumped to the new file. the resulting file should look like this...

;TestingBS
;company.testing=BS

;New Value
value.new=1


I've been trying a few things, but I can't get it quite right. If I do get the new value in the output, the company.testing appears both commented and uncommented.

Can anyone think of a quick way to do this?

VS 2015 Displaying array columns onto a form

$
0
0
Our programming takes input from Form1, does a lot of comparing and qualifying, and ends up storing final data results into an array named displayArray().

Now, we want to show a Form2 that opens displaying the first column of the displayArray, and lets the user step through the array records with buttons labeled Previous and Next.

How do we map a selected array column and selected rows to form fields on Form2?

And, how to create the Previous and Next controls that change the displayed array column?

Replacement for Picturebox?

$
0
0
Hi. I need replacing my picture box. The Picture box was good for testing but now that I want to progress with game development I need to have something that will be able to properly collide with objects, E.g. Instead of legs jumping onto object, Corner of picture box hits and looks like character is floating in air. Or transparency, E.g. to be able to see through characters legs and see other objects or Form background.

I use animation for my character which currently is layered into a GIF format in the picture box. Also if you say BMP than your going to have to very carefully explain everything thats going on and why because I tried BMP but I didnt get it

Thanks in advance! I really need help with this one as it plays a crucial role in further development! :)

Edit: Here is the code also if it helps. As you may tell alot of things are currently working with the pictureboxes so it' gonna be a pain when I have to change everything but if theirs also a way I dont tha'd be helpful too :)

Code:

Public Class Form1
    Dim blnJump As Boolean = True

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        My.Computer.Audio.Play(My.Resources.backround, AudioPlayMode.BackgroundLoop)

    End Sub

    'Will Control the key functions and activate asociated timers
    Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown

        Select Case e.KeyCode
            Case Keys.Right
                tmrRight.Enabled = True
                tmrLeft.Enabled = False
                Me.picPlayer.Image = My.Resources.Idle_Right
            Case Keys.Left
                tmrLeft.Enabled = True
                tmrRight.Enabled = False
                Me.picPlayer.Image = My.Resources.Idle_Left
            Case Keys.Up
                If blnJump = True Then
                    tmrUp.Enabled = True
                    blnJump = False
                    x = 0
                End If

        End Select

    End Sub


    Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp

        Select Case e.KeyCode
            Case Keys.Right
                tmrRight.Enabled = False
            Case Keys.Left
                tmrLeft.Enabled = False

        End Select

    End Sub

    'Controls move left timer
    Private Sub tmrLeft_Tick(sender As Object, e As EventArgs) Handles tmrLeft.Tick

        If picPlayer.Bounds.IntersectsWith(PictureBox2.Bounds) Then
            If tmrLeft.Enabled = True Then
                tmrLeft.Enabled = False
                picPlayer.Left = picPlayer.Left + 5
            End If
        Else
            picPlayer.Left = picPlayer.Left - 5
        End If

    End Sub

    'Controls move right timer
    Private Sub tmrRight_Tick(sender As Object, e As EventArgs) Handles tmrRight.Tick

        If picPlayer.Bounds.IntersectsWith(PictureBox2.Bounds) Then
            If tmrRight.Enabled = True Then
                tmrRight.Enabled = False
                picPlayer.Left = picPlayer.Left - 5
            End If
        Else
            picPlayer.Left = picPlayer.Left + 5
        End If

    End Sub

    Private x As Integer = 0

    'Controls Jump timer
    Private Sub tmrUp_Tick(sender As Object, e As EventArgs) Handles tmrUp.Tick

        If x < 20 Then
            picPlayer.Top -= 10
        Else
            tmrUp.Enabled = False
            tmrDown.Enabled = True
        End If
        x += 1
    End Sub

    'Controls fall/move down timer
    Private Sub tmrDown_Tick(sender As Object, e As EventArgs) Handles tmrDown.Tick
        picPlayer.Top += 10
        Dim picOBJ() As Rectangle = {picGround.Bounds, PictureBox2.Bounds}

        For index As Integer = 0 To picOBJ.Length - 1
            If picPlayer.Bounds.IntersectsWith(picOBJ(index)) Then
                blnJump = True
                tmrDown.Enabled = False
            End If
        Next

    End Sub


End Class


optional parameters must have a default value.

$
0
0
Ok understood. I am translating net 1.0 to 2.0 for windows 7 compatibility in a dll for a project.
I have this
Code:

Public Overridable Sub DisplayThumbs(ByVal Optional thumbNumber As Object, ByVal Optional [option] As Object)
    If (Me.ocx Is Nothing) Then
      Throw New InvalidActiveXStateException("DisplayThumbs", ActiveXInvokeKind.MethodInvoke)
    End If
 Me.ocx.DisplayThumbs(thumbNumber, [option])

Is this simply fixable by adding a = nothing or with that cause more problems?

Session Restore & version of IE?

$
0
0
So I am currently sadly using the IE control for a basic webbrowser project, and from what I have read it claims that it is the version installed on your computer. However I tested it on a site a few weeks ago and it said that it was IE 7 and I have IE 11 installed on my computer, why is this difference? And my second question is with the IE control Can you do Session Restore? Idk if you can use java with VB but I have also read session restore is mostly in java? Any help is appreciated.

VS 2015 Property not working.

$
0
0
Hi folks.

I'm still playing about with this text box class of mine. It's a class that inherits a textbox and has a few optional properties. A couple of these properties are enums, these work fine in the property window and can be set without any problems.

But I have another property which is a string. This property shows up in the property window and I can type into it, but as soon as I press Enter it forgets what I've typed in. It's a very simple public property with a get and a let which are setup up correctly.

Any ideas?

Object Required 424

$
0
0
I am A soldier currently deployed to afghnistan and we are trying to make a VB code run but keep getting an object required 424 error. Can someone please tell me what the problem is im stumped. When the debugger is run the line in all caps and maked is the one that comes up as an issue.



Option Compare Database
Sub PrintCert()

Dim wdDoc As New Word.Application
'Dim wdDoc As MailMerge
Dim mergeDoc As Word.Document
Dim BookNumber As Integer
Dim awardType As String
Dim wordDocument As String
Dim DIR As String
Dim strTable As String
Dim strWorksheetPath As String

BookNumber = fGetBookNumber

If (BookNumber = -1) Then

awardType = fGetAwardTypeIndiv()
Else
awardType = fGetAwardType(BookNumber)

End If

'O:\Actions\Active\0200-02U CY11 Awards (Individual, Civilian, Unit, Casualty)\Individual\

If (fIsIJC(BookNumber)) Then
DIR = "O:\Actions\Active\0200-02U CY11 Awards (Individual, Civilian, Unit, Casualty)\Individual\IJC Mail Merge Docs\"
Else
DIR = "O:\Actions\Active\0200-02U CY11 Awards (Individual, Civilian, Unit, Casualty)\Individual\Mail Merge Docs\"
End If

Const saveDIR = "O:\Actions\Active\0200-02U CY11 Awards (Individual, Civilian, Unit, Casualty)\Individual\Saved Certs\"
wordDocument = DIR & awardType & "New.doc"


'Set wdDoc = New Word.Application
wdDoc.Application.Visible = False
'wdDoc.Visible = True
'wdDoc.Documents.Open wordDocument
===============SET MERGEDOC = WDDOCX.DOCUMENTS.OPEN(WORDDOCUMENT, FALSE, TRUE)=========[/I]
'wdDoc.Activate

'O:\Actions\Active\0200-02U CY11 Awards (Individual, Civilian, Unit, Casualty)\Individual\(1) Individual Awards dBase Live

With mergeDoc.MailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource _
Name:="O:\Actions\Active\0200-02U CY11 Awards (Individual, Civilian, Unit, Casualty)" & _
"\Individual\(1) Individual Awards dBase Live\Individual Awards Tracker v2.0_be.accdb", _
LinkToSource:=True, AddToRecentFiles:=False, _
SQLStatement:="SELECT * FROM [tblMailMerge]"
'Connection:="TABLE tblMailMerge", _

End With
mergeDoc.MailMerge.Execute
wdDoc.Application.DisplayAlerts = wdAlertsNone
wdDoc.Application.PrintOut Background:=False
'wdDoc.Application.ActiveDocument.PrintOut
wdDoc.Application.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
saveDIR & awardType & Format(Now(), "yyyymmddhhmmss") & ".pdf", ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False

wdDoc.Application.ActiveDocument.Close (False)

VS 2015 Placing a user created object on a form for the first time.

$
0
0
Hi folks, me again.

Quick and easy question today. I hope.

I have a user made object, a class that inherits a label, which then I do a load of stuff with. All that's fine.

However this object is going to resize itself with a change of the underlying forms size. I think I'm going to be ok with all that, but I'm kind of stuck at the first hurdle, which is getting the object to resize when the user first drags it to the form from the toolbar. This is functionality it must have, The same as a menu bar does, or a status bar.

Everything I've tried so far that makes any kind of sense creates a Null Reference error when placing the object, as it's not created before the code runs, so any reference to itself seems to be failing. I think that's what going on.

Any help would be very gratefully received, and although the Christmas season is passed I might consider sending some mince pies.

Thanks.
Viewing all 27409 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>