Cannot print in VB2010 Windows Forms using Microsoft.VisualBasic.Compatibility.VB6 - winforms

I am trying to print from VB2010 Windows Forms using the Microsoft.VisualBasic.Compatibility.VB6 library.
I have downloaded the library and imported it onto my form. The Microsoft help files are inaccurate and incomplete, and there is not a complete example. A simple form with a print button that prints "Hello World!" to the default system printer would be enough to get me started.
Thanking you in advance for any help offered...

Using the proper library will go a long end to making this simple. Use the PrintDocument class instead:
Imports System.Drawing.Printing
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim doc = New PrintDocument()
AddHandler doc.PrintPage, AddressOf PrintHello
doc.Print()
End Sub
Private Sub PrintHello(sender As Object, e As PrintPageEventArgs)
e.Graphics.DrawString("Hello world", Me.Font, Brushes.Black, New PointF(0, 0))
End Sub
End Class

Related

Problem Opening SQLite Connection in VB.net

I am trying to learn SQLLite (Years of Experience with apps using SQL Server). I am going slowly and right off the bat I could not open a connection to a database created in SQLite Studio. I have tried a number of different examples with no luck. I first tried with a Nuget package and then went to the SQLite website and downloaded the 64-bit binaries for .Net 4.5. I get this error no matter what I try: system.BadImageFormatException.
Can someone please tell me what I'm doing wrong or point me to an example that really works?
Thanks!!!
Imports System.Data.SQLite
Public Class Form1
Private connectionstring As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim exePath As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath)
Dim dbPath As String = exePath & "\NamesTest.db"
connectionstring = "Data Source=" & dbPath
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim SQLiteConn As New SQLiteConnection(connectionstring)
SQLiteConn.Open()
End Sub
End Class

My checklistbox doesn't display my array in VB

I'm writing a program to be used by my library as a step by step checklist when adding new materials (books) to the collection.
Option Explicit On
Option Strict On
Public Class frmCircCounter
Public ReadOnly Property Items As CheckedListBox.ObjectCollection
'confirms all boxes have been checked, and clears them
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'If
' End If
End Sub
Private Sub CheckedListBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CheckedListBox4.SelectedIndexChanged
'I'm not sure what this is for the internet told me to add this?
InitializeComponent()
'establishes the arrary displayed in the checklistbox
Dim strProperPackage() As String = {"Call Number and Authors Last name?", "Sub-Category Sticker?", "Plastic Wrapping on the Cover if needed?"}
'displays it... or it should!!!?
clbProperPackage.Items.AddRange(strProperPackage)
End Sub
End Class
I expect to have the array displayed in the CLB upon execution
Try looping through your array and add each item into it.
For Each item As String In strProperPackage
clbProperPackage.Items.Add(item)
Next
Your script will not execute the correct way because your using selected index changed but this will only run when a item has been selected in the list.
The best way to test this is by creating a new button and assigning this code to that button. With the button, the script will execute on click.
Public sub btnAccept (sender as object, e and eventargs) handles btnAccept.click
Dim strProperPackage() As String = {"Call Number and Authors Last name?", "Sub-Category Sticker?", "Plastic Wrapping on the Cover if needed?"}
'displays it... or it should!!!? clbProperPackage.Items.AddRange(strProperPackage)
End Sub

Update a MS Access database in VB.NET

This is my first post on stackoverflow so please hang with me. I am attempting to update an access database using VB.NET. Using the following series of videos (starting with this one), we have been able to properly use our form to save new data into the access database.
https://www.youtube.com/results?search_query=vb.net+ms+access+database+tutorial+1+%23+add+new+remove+save+data+in+database+using+vb.net
However, when we start up the form again after opening up access to make sure the updates have occurred (which they always do), none of our changes are there. And when we open up access again the changes we made that showed up in the access database are gone, and the access database goes back to its original state (the state it was when we linked it to visual studio in the first place).
Below is the code we have so far, we appreciate any help you can give us!
Thanks.
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Sheet1BindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Sheet1BindingNavigatorSaveItem.Click
Me.Validate()
Me.Sheet1BindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(MIS275_Small_BusinessDataSet)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MIS275_Small_BusinessDataSet.Sheet1' table. You can move, or remove it, as needed.
Timer1.Start()
Me.Sheet1TableAdapter.Fill(MIS275_Small_BusinessDataSet.Sheet1)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Sheet1BindingSource.AddNew()
End Sub
Private Sub Save_Click(sender As Object, e As EventArgs) Handles Save.Click
Try
Sheet1BindingSource.EndEdit()
Sheet1TableAdapter.Update(MIS275_Small_BusinessDataSet.Sheet1)
MessageBox.Show("Data Saved")
Catch ex As Exception
MessageBox.Show("Error")
End Try
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim count As Integer
count = Sheet1BindingSource.Count
End Sub
End Class

How to implement a Windows Form in vb2008 in vb6

I have written a Test-Form in vb2008 in order to call it as a mdi-child in vb6:
The code is as followed:
`
Imports System.Runtime.InteropServices
<ComClass(frmTest.ClassId, frmTest.InterfaceId, frmTest.EventsId)> _
Public Class frmTest
Inherits System.Windows.Forms.Form
#Region "COM-GUIDs"
Public Const ClassId As String = ""
Public Const InterfaceId As String = ""
Public Const EventsId As String = ""
#End Region
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Public Overloads Sub Show(ByVal MDI As Object)
Me.MdiParent = CType(MDI, System.Windows.Forms.Form)
Me.Show
End Sub
Public Sub SomeText(ByVal Text As String)
MsgBox(Text)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("Test")
End Sub
End Class
`
In vb6, under references I make a reference to the tlb.
So far, so good.
I open a new project and create a new MDI-Form.
Private Sub Start_Click(Index As Integer)
Dim f As New MyTestLibrary.frmTest
f.Show (Me)
End Sub
Unfortunately, this approach does not work, because it is COM-Component, and an error occurs. Anyone knows a verified way to make a windows .NET form available in VB6 ???
Thank you, in advance.
Stephan
Put your VB 6 in a DLL. Create a public method that invokes a modal dialog from VB 6.
From your .NET program, reference the DLL built in VB 6 (COM tab)
Invoke the method. Your VB6 modal form will appear.
However, some things may not work such as some ActiveX controls embedded in the VB 6 code might have problems.

Passing of variable value from one form another

im just wondering on how can i pass value of a variable to another form from a different form
I have a form called frmSearch then I have another form called frmMain from frmSearch i have a varible A which is publicly declared and i wanted the value of A to frmMain i've tried the following
frmMain
dim B = frmSearch.A
but everytime i checked the value of B it always returns a blank string
also when i checked the value of frmSearch.A it also returns nothing even though it returns a value when i checked it in frmSearch
please help im really stuck
thanks in advance
Accessing a field of a form shouldn't be a problem. Just make sure that at the time you are reading the field it is already assigned.
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim form = New Form2
Debug.Assert(form.A Is Nothing)
form.ShowDialog()
Debug.WriteLine(form.A(0))
End Sub
End Class
Public Class Form2
Public A As String()
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
A = {"abc", "aaa"}
End Sub
End Class

Resources