Error: Form1 is a type of windowsApplication cannot be used as an expression - vb.net

How to solve error when passing and returning some data across the form in visual basic.
Error: Form1 is a type of windowsApplication cannot be used as an
expression
showin error on "Form 1" (Public Class Form1)
FORM 1 CODE
Public Class Form1
Dim eid As String = ""
Public Sub New(ByVal empid As String)
InitializeComponent()
eid = empid
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare a variable of string type
Dim pass As String = TextBox1.Text
Dim frm As New Form2(pass)
frm.ShowDialog()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label2.Text = eid.ToString()
End Sub
End Class
FORM 2 CODE
Public Class Form2
Dim eid As String = ""
Public Sub New(ByVal empid As String)
InitializeComponent()
eid = empid
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = eid.ToString()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim value As String = TextBox2.Text
Dim fr As New Form1(value)
fr.ShowDialog()
End Sub
End Class

To solve your error message add this to your Form1 Class
Public Sub New()
InitializeComponent()
End Sub
If you are trying to pass values between forms, you might find this link useful...
http://grantwinney.com/passing-data-between-two-forms-in-winforms/

Public Class Form1
Dim eid As String = ""
Public Sub New(ByVal empid As String)
InitializeComponent()
eid = empid
End Sub
Public Sub New()
InitializeComponent()
End Sub
startup form isn't being called with any parameters
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare a variable of string type
Dim pass As String = TextBox1.Text
Dim frm As New Form2(pass)
frm.ShowDialog()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label2.Text = eid.ToString()
End Sub
End Class

It happens when you change the project type from class library to windows forms in visual studio.
Head to Application.Designer.vb in your project and there you'll find something like this:
Namespace My
'NOTE: This file is auto-generated; do not modify it directly. To make changes,
' or if you encounter build errors in this file, go to the Project Designer
' (go to Project Properties or double-click the My Project node in
' Solution Explorer), and make changes on the Application tab.
'
Partial Friend Class MyApplication
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Sub New()
MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
Me.IsSingleInstance = false
Me.EnableVisualStyles = true
Me.SaveMySettingsOnExit = true
Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
End Sub
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.AeonLabs.Layouts.Main.mainAppLayoutForm
End Sub
End Class
End Namespace
in the sub OnCreateMainForm() where it has OnCreateMainForm change it to something like this
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = New Global.AeonLabs.Layouts.Main.mainAppLayoutForm
End Sub
and you'll be good to go!!

Related

How to generate an Outlook ribbon?

I'm trying to create an Outlook ribbon using a VB VSTO program.
I don't receive any error. I don't receive the ribbon.
My code:
Public Class ThisAddIn
Private Sub ThisAddIn_Startup(sender As Object, e As System.EventArgs)
'Handles Me.Startup
End Sub
Public Class ReadPublishing
Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As
RibbonUIEventArgs) Handles MyBase.Load
End Sub
Private Sub btnPDF_Click(sender As Object, e As RibbonControlEventArgs)
Handles btnPDF.Click
Dim desktopFolder, fileName As String
desktopFolder = Environment.GetFolderPath
(Environment.SpecialFolder.Desktop)
fileName = "You press the black one"
' --- insert action
End Sub
End Class
Private Sub ThisAddIn_Shutdown(sender As Object, e As System.EventArgs)
'Handles Me.Shutdown
End Sub
End Class

How to interact with Listbox from Form2 throught thread from Form1

I tried to add items to Listbox in Form2 but noting can't be added, when I put listbox in same form where is thread it works good...Could someone help to make it work with Form2? Here is code:
Public Class Form1
Dim testthread As Threading.Thread
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Control.CheckForIllegalCrossThreadCalls = False
testthread = New Threading.Thread(AddressOf testira)
testthread.Start()
End Sub
Sub testira()
Form2.ListBox1.Items.Add(TextBox1.Text)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form2.Show()
End Sub
End Class
Here's an example...
Public Class Form1
Private f2 As New Form2
Private Delegate Sub AddItemDelegate(ByVal item As String)
Private Delegate Function GetTextboxTextDelegate(ByVal TB As TextBox) As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim testthread As New Threading.Thread(AddressOf testira)
testthread.Start()
End Sub
Sub testira()
Dim item As String = GetTextboxText(TextBox1)
AddItem(item)
End Sub
Private Function GetTextboxText(ByVal TB As TextBox) As String
If TB.InvokeRequired Then
Return TB.Invoke(New GetTextboxTextDelegate(AddressOf GetTextboxText), New Object() {TB})
Else
Return TB.Text
End If
End Function
Private Sub AddItem(ByVal item As String)
If Me.InvokeRequired Then
Me.Invoke(New AddItemDelegate(AddressOf AddItem), New Object() {item})
Else
If IsNothing(f2) OrElse f2.IsDisposed Then
f2 = New Form2
End If
f2.ListBox1.Items.Add(item)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If IsNothing(f2) OrElse f2.IsDisposed Then
f2 = New Form2
End If
f2.Show()
End Sub
End Class

How to retrieve the value from one form to another in vb.net

I have the problem to retreive the string from one form to another. here is my code: What's wrong with this?
Public Class Form3
Dim unit As String
Public itmname As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim obj1 As New Form4
itmname = tb1.Text
MessageBox.Show(itmname)
obj1.Label1.Text = itmname
obj1.Show()
End Sub
End Class
Public Class Form4
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Form3
MessageBox.Show("item name:" + .itmname)
Label1.Text = .itmname
End With
End Sub
End Class
You shouldn't have to do any special code in Form4 to set the value. you already set the textbox value from from3's button click event. Setting again is just overwriting it with a blank value from a newly instantiated form. Just clear all the code you have listed in Form4's load event and it should work.

Error in programming

Imports SpeechLib
Public Class Form1
Public vox = CreateObject("sapi.spvoice")
Private Sub cmdSpeak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSpeak.Click
Dim t As String = "Hello , This is a Text"
Say(t)
End Sub
Public Sub Say(ByVal text As String)
vox.Speak(text,SpeechVoiceSpeakFlags.SVSFlagsAsync)
End Sub
Private Sub cmdPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPause.Click
vox.pause()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
vox.AlertBoundary = SVEPhoneme
End Sub
End Class
I am getting an error
Name 'SVEPhoneme' is not declared.
How and where do I declare it ?
It is SpeechVoiceEvents.SVEPhoneme
This is all a lot easier if you make this code early bound:
Public vox as New SpVoice
Or better yet, use the .NET wrapper for the sapi, System.Speech assembly.
Imports System.Speech.Synthesis
Public Class Form1
Public vox As New SpeechSynthesizer
Public Sub Say(ByVal text As String)
vox.SpeakAsync(text)
End Sub
End Class
SVEPhoneme represents the Phoneme event, which occurs when the engine completes a phoneme while speaking.
Try setting SVEPhoneme to be the integer 64.
http://msdn.microsoft.com/en-us/library/ms720886(v=vs.85).asp

how to store string in date in vb.net?

how to store string value in date variable in vb.net
i am using the following code
dim dtBL as Date
txtBLDate.text="23/11/2010"
dtBL = Format(CDate(txtBLDate.Text), "MM/dd/yyyy")
but i am getting the error which says that 'Conversion from string "23/11/2010" to type 'Date' is not valid.'
please advice on this
Two rules of thumb I give everyone with VB.Net:
Turn Option Strict On
Abandon the Microsoft.VisualBasic-Namespace ASAP
To answer your question, your date is in the format dd/MM/yyyy and not MM/dd/yyyy.
i am using vb.net in web applications
i put a page code that may be helping you dealing with dates
ASPX
code behind
Partial Class DateFormatConversions Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
lblDate.Text = Today.ToString("M/d/yyyy")
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
lblDate.Text = Today.ToString("MM/dd/yyyy")
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
lblDate.Text = Today.ToString("d/M/yyyy")
End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
lblDate.Text = Today.ToString("dd/MM/yyyy")
End Sub
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim DTFI As New System.Globalization.DateTimeFormatInfo
DTFI.ShortDatePattern = DropDownList1.SelectedValue
Dim addedDate As DateTime
addedDate = DateTime.Parse(TextBox1.Text, DTFI)
lblDateOutput.Text = addedDate.ToLongDateString
End Sub End Class
Imports Microsoft.VisualBasic Imports System.Globalization Public Class DatumKonvert1 Public Shared Function DK1(ByVal myDMstring As String) As Date
Dim source As String = myDMstring
Dim d As DateTime = DateTime.ParseExact(source, "d'/'M'/'yyyy", CultureInfo.InvariantCulture)
Dim resultMydate As String = d.ToString("M'/'d'/'yyyy")
Dim mdx = DateTime.ParseExact(resultMydate, "M'/'d'/'yyyy", CultureInfo.InvariantCulture)
Return mdx End Function End Class