how pass a parameter to onload function??
<body onLoad="myFunction(<%=myVar%>)">
It crashes.
The parameter is a vb variable defined with Dim
The function is a vbscript function
Urgent HELP
Private Sub cmdClear_Click()
Dim Confirm As Integer
Confirm = MsgBox("Are you sure you want clear this Sheet?", vbYesNo, "WARNING: Date Changed")
If Confirm = 6 Then
Sheets("OPV").Activate
'Sheets("OPV").Activate
Sheets("OPV").Range("B4:BZ1000").ClearContents
Sheets("OPV").Range("B4:BZ1000").Interior.Pattern = xlNone
Sheets("OPV").Activate
Sheets("OPV").Range("B4").Activate
MsgBox " Done .. ", vbInformation, "Clear ......"
End If
End Sub
what should be the parameter for create object the following code
dim a
set a=CreateObject("Collection") //getting a runtime error saying ActiveX
//component can't create object: 'Collection
a.add(CreateObject("Collection"))
a.Items(0).Add(1)
MsgBox(a.Items(0).count)
MsgBox(a.Items(0).Item(0))
How to make a link button visible after another button has been clicked in asp.net(vb) in button_click()
it says error as "Object reference not set to an instance of an object."
i've done this in my code
Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim receipt As LinkButton = FormView1.FindControl("LinkButton1")
' receipt.Enabled = "true"
' receipt.EnableTheming = "true"
' receipt.EnableViewState = "true"
receipt.Visible = "true"
End Sub
Suppose I have some code that looks like this:
Private Sub MySub()
dim blnFlag as Boolean
blnFlag = False
for each item in collection
if item.Name = "Mike" then
blnFound = true
exit for
endif
next item
End Sub
Now - the blnFLag = False assignment is not actually necessary - booleans are initialised as false, but I think it's inclusion makes the code easier to read. What's your opinion?
I need to have the following : (name1 + "a") + (name2 + "a") + ...
Dim separator() As String = {"|"}
myString.Split(separator, StringSplitOptions.None).SomeLinq(...)
I don't know what to add at the end to add an "a" to each element...
this if it works should check the internet connection if there is a connection it does nothing. if there isn't a connection it should write a error in a txtfile if that happend 5 times it should create a error but it doesn't
I will show you the whole code that i have now and the piece of code that i want in a loop. I can't get it in the way i want. I want it to creat 1 Event-error after 5 times writing to the file.
this is the whole code i will put the code i want in a loop under it
strDirectory = "Z:\text2"
strFile = "\foutmelding.txt"
strText = "De connectie is verbroken"
strWebsite = "www.helmichbeens.com"
If PingSite(strWebsite) Then WScript.Quit 'Website is pingable - no further action required
Set objFSO = CreateObject("Scripting.FileSystemObject")
RecordSingleEvent
Dim fout
For fout = 1 To 5 : Do
If fout = 5 Then Exit Do
Set WshShell = WScript.CreateObject("WScript.Shell")
Call WshShell.LogEvent(1, "Test Event")
Loop While False : next
'------------------------------------
'Record a single event in a text file
'------------------------------------
Sub RecordSingleEvent
If Not objFSO.FolderExists(strDirectory) Then objFSO.CreateFolder(strDirectory)
Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, 8, True)
objTextFile.WriteLine(Now & strText)
objTextFile.Close
End sub
'----------------
'Ping my web site
'----------------
Function PingSite( myWebsite )
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
objHTTP.Open "GET", "http://" & myWebsite & "/", False
objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"
On Error Resume Next
objHTTP.Send
PingSite = (objHTTP.Status = 200)
On Error Goto 0
End Function
'-----------------------------------------------
'Counts the number of lines inside the text file
'-----------------------------------------------
Function EventCount(fout)
strData = objFSO.OpenTextFile(strDirectory & strFile,ForReading).ReadAll
arrLines = Split(strData,vbCrLf)
EventCount = UBound(arrLines)
End Function
This is the whole code, and it doesnt work correctly becaus it creats a event-log rightaway and it should do that after the script has written 5 times to the textfile
here is the code that writes to a textfile
Sub RecordSingleEvent
If Not objFSO.FolderExists(strDirectory) Then objFSO.CreateFolder(strDirectory)
Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, 8, True)
objTextFile.WriteLine(Now & strText)
objTextFile.Close
End sub
and here is the code but this part doesnt not work or atleast i think it is this part
Dim fout
For fout = 1 To 5 : Do
If fout = 5 Then Exit Do
Set WshShell = WScript.CreateObject("WScript.Shell")
Call WshShell.LogEvent(1, "Test Event")
Loop While False : next
Function EventCount(fout)
strData = objFSO.OpenTextFile(strDirectory & strFile,ForReading).ReadAll
arrLines = Split(strData,vbCrLf)
EventCount = UBound(arrLines)
End Function
this is the not working part and I don't know what to do anymore so can you please take a look at it tank you very much.
btw: this code can be very usefull for a network administrator
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim allowedChars As String = "0123456789$,"
If allowedChars.IndexOf(e.KeyChar) = -1 Then
' Invalid Character
e.Handled = True
End If
End Sub
this code accept only digits and its working like a charm but if i typed a wrong number its not allowing me to use the delete or the backspace on the keyboard how to solve this problem ?
I am dynamically creating a report, where I create a worksheet, bring in the records afresh. How can I easily type the field names and copy them to the cells. Without doing one cell per line, there are ~20 columns.
I tried:
dim fieldNames as variant
fieldNames = ("'DS Date', 'A', 'B', 'A','S ASD', 'S','D S','D S', 'S','D S', 'SD', 'S','D'")
Sheets("DATA").Range("C14:W14").Value = Application.WorksheetFunction.Transpose(fieldNames)
But it just posts the whole thing in each cell? Any ideas?
I have used the connection string below but I am getting an error when trying to create a table
Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFName + _
";Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1"""
Cannot modify the design of table 'tablename'. It is in a read-only database.
What function in Excel simply takes a string parameter and runs the command? It would work just like the OK button in the Start - Run dialog.
Dim myCommand as String
myCommand = "excel C:\Documents and Settings\JohnDoe\Desktop\test.xls"
Run(myCommand)
I am coding in Visual Basic. I am using a checkbox control. Now depending on its checked property I need to set/unset a bit column in a SQL Server database. Here's the code:
Try
conSQL.Open()
Dim cmd As New SqlCommand("update Student set send_mail = " + _
sendemailCheckBox.Checked.ToString + " where student_id = '" _
+ sidnolabel.Text + "'", conSQL)
cmd.ExecuteNonQuery()
Finally
conSQL.Close()
End Try
The send_mail attribute is of bit datatype. This code is not working.
How do I go about it?
I have done
Dim qd as querydef
set qd = Querydefs("MyQuery")
set qd.sql = "..."
In debug qd.sql has been updated but the physical MyQuery still contains the old sql.
How to update this physical query ?
Hello how can I have like a catalog for a property in .net VB .. I mean if i have
Property funcion(ByVal _funcion As Int16) As Int16
Get
Return _funcion
End Get
Set(ByVal value As Int16)
_funcion = value
End Set
End Property
I want to be able to assign to this property a limited number of options.
Example ..
Dim a as trick (the class )
a.funcion = (and get a list of possible attributes) ...
Thanks !!!
question: how can i bind the same vector, lets say o=c(1,2,3,4) mutiple times to get a matrix like
o=array(c(1,2,3,4,1,2,3,4,1,2,3,4), dim(c(4,3))
o
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 2 2 2
[3,] 3 3 3
[4,] 4 4 4
in a nicer way then: o=cbind(o,o,o) and maybe more generalized (dublicate()??
I need this to specifiy colors for elements in textplot()
thx a lot
Can I convert my VB code to C++? How can I do it?
This is my VB code:
Dim OpenFileDialog1 As New OpenFileDialog
With OpenFileDialog1
.CheckFileExists = True
.ShowReadOnly = False
.Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg"
.FilterIndex = 2
If .ShowDialog = DialogResult.OK Then
' Load the specified file into a PictureBox control.
PictureBox1.Image = Image.FromFile(.FileName)
End If
End With
I'm creating a reporting application, and our customers are going to need to generate some pretty big reports which require quite a bit of memory. Ive been in a re-factoring mood lately, so I was wondering what the best way to access the properties of another open form would be(The reporting viewer opens in a new form.) So far I have:
Dim form As MainSelections
form = My.Application.OpenForms(2)
yay or nay.
Thanks
I'm trying to write a simple/small Windows Communication Foundation service application in Visual Basic (but I am very novice in VB) and all the good examples I've found on the net are written in C#. So far I've gotten my WCF service application working but now I'm trying to add callback functionality and the program has gotten more complicated. In the C# example code I understand how everything works but I am having trouble translating into VB the portion of code that uses a delegate. Can someone please show the VB equivalent?
Here is the C# code sample I'm using for reference:
namespace WCFCallbacks
{
using System;
using System.ServiceModel;
[ServiceContract(CallbackContract = typeof(IMessageCallback))]
public interface IMessage
{
[OperationContract]
void AddMessage(string message);
[OperationContract]
bool Subscribe();
[OperationContract]
bool Unsubscribe();
}
interface IMessageCallback
{
[OperationContract(IsOneWay = true)]
void OnMessageAdded(string message, DateTime timestamp);
}
}
namespace WCFCallbacks
{
using System;
using System.Collections.Generic;
using System.ServiceModel;
public class MessageService : IMessage
{
private static readonly List<IMessageCallback> subscribers = new List<IMessageCallback>();
//The code in this AddMessage method is what I'd like to see re-written in VB...
public void AddMessage(string message)
{
subscribers.ForEach(delegate(IMessageCallback callback)
{
if (((ICommunicationObject)callback).State == CommunicationState.Opened)
{
callback.OnMessageAdded(message, DateTime.Now);
}
else
{
subscribers.Remove(callback);
}
});
}
public bool Subscribe()
{
try
{
IMessageCallback callback = OperationContext.Current.GetCallbackChannel<IMessageCallback>();
if (!subscribers.Contains(callback))
subscribers.Add(callback);
return true;
}
catch
{
return false;
}
}
public bool Unsubscribe()
{
try
{
IMessageCallback callback = OperationContext.Current.GetCallbackChannel<IMessageCallback>();
if (!subscribers.Contains(callback))
subscribers.Remove(callback);
return true;
}
catch
{
return false;
}
}
}
}
I was thinking I could do something like this but I don't know how to pass the message string from AddMessage to DoSomething...
Dim subscribers As New List(Of IMessageCallback)
Public Sub AddMessage(ByVal message As String) Implements IMessage.AddMessage
Dim action As Action(Of IMessageCallback)
action = AddressOf DoSomething
subscribers.ForEach(action)
'Or this instead of the above three lines:
'subscribers.ForEach(AddressOf DoSomething)
End Sub
Public Sub DoSomething(ByVal callback As IMessageCallback)
'I am also confused by:
'((ICommunicationObject)callback).State
'Is that casting the callback object as type ICommunicationObject?
'How is that done in VB?
End Sub
I'm writing a macro, but because I'm working for first time in vb, I faced problems.
My code:
Cells (1, 1).Select
Dim tempvar As Integer
tempvar = Val(Selection.Value) // error
Selection.Value = tempvar + 1
What my code should be:
Cells(1,1).Value+=1
I get error "type mismatch". How do I accomplish that?
my application builds a pdf with images
in the solution explorer i added a folder called pics and dropped all the images there
when i run the program from my computer, there are no problems, but when i had a different user install the application they get this error:
here's how i am including the image:
Dim jpeg2 As Image = Image.GetInstance(Application.StartupPath & "\pics\1.jpg")
i am using the itextsharp library
why is the user having this problem?
Why does the following display 12/31/1600 ???
Imports System.IO
Module Module1
Sub Main()
Dim fi As New FileInfo("DocFiles\phillips_phone_number.txt")
Console.WriteLine(fi.FullName)
Console.WriteLine(fi.LastAccessTime.ToShortDateString)
Console.ReadKey()
End Sub
End Module
I have a code like this:
Dim strResponses As String
strResponses = Forms!frmResponses.QstnID.OpenArgs
If Len(strResponses) 0 Then
Me![QstnID].DefaultValue = Me.OpenArgs
End If
When I run it, its gives error 438. Can someone help me to know where the error is?
I'm trying to copy an existing sheet in my workbook and then I want to use the copied sheet to run the rest of my code.
(Sheet3 is the existing sheet, S_Temp is the copied sheet)
Dim s_Temp as string
Sheet3.copy
Activesheet.name = S_Temp
Sheets("S_Temp").Range("A1").value = "Test"
How can I reference to the copied sheet?
here's my code:
Public Sub SendSMS()
Dim n As Integer
n = FreeFile
' Change the string below if using a different COM port or the port speed
Open "COM3:9600,N,8,1" For Output As #n
Print #n, "AT"
Close #n
End Sub
i'm trying to connect to my phone that is attached to this computer.
how do i catch responses to my AT COMMANDS? in hyperterminal you see responses right away, i want to be able to see them here as well, how do i do it?