Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Invalid Use Of New Keyword


Hi all,

Yes this is the error that i got today..
Yesterday i've added the following references from Project menu:

MS Access 9 Object library
MS Activex Data Objects 2.7
MS ADO extension 2.5

Yesterday the same code was working, today VB returned that error , the code is below :

' this is a module
' ---------------
Option Explicit

Public AdoUUT As Recordset
Dim db As Connection


Public Sub Setupdb(ServerUser As String, ServerIP As String)

Set db = New Connection ' here VB return the error


even removing the above references now VB is stuck at that line...
Why VB cannot create the connection anymore ?

please reply..
thanks, alex




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Invalid Use Of New Keyword
I have a program I use at work and I brought it home the other night. When I tried to save it on my computer I got an error saying I was using an invalid use of "NEW" keyword. I kow at work I have service pack 4 but not at home. Is this the problem? It seems like the sp4 was a large download and I'm not sure if it is needed.

Thanks,

Eric

Dim appExcel As Excel.Application
Set appExcel = New Excel.Application ''<=====Error here''
appExcel.Workbooks.Open mstrInputFileName
appExcel.DisplayAlerts = False
appExcel.ActiveWorkbook.SaveAs mstrinputFileExcellHold, xlTextMSDOS
appExcel.Quit
Set appExcel = Nothing
mstrInputFileName = mstrinputFileExcellHold
MsgBox "tab text created", vbOKOnly

Invalid Use Of New Keyword
Whenever I connect to a database using the data form wizard, it works fine but as soon as I put the code into my project I get the "Invalid use of New keyword" error. Here's my code:

Dim db As Connection
Set db = New Connection
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:Documents and Settings homMy DocumentsTerrys Turkeys est1.mdb;"

Invalid Use Of New Keyword
I have run into problems with my Logging program, it uses an api 'fEnumWindows' to grab the current applications running and has a byval for a listbox.

I am running the core of the program formless. I believe it is a problem with VB 6 where you can't create a list box without having on already on a form.

my code:


Code:
Dim lstApps As ListBox

Set lstApps = New ListBox


MSDN advises me nicely that a ListBox is not a createable item and that to use a listbox that is on the form list1 for example. This is not an option for me, Any ideas? I have tried to load a VB5 commctl library to get the listbox but no go....

Thanks in advance all.

Invalid Use Of NEW Keyword
Am I missing something or has my brain taken a early holiday?


Code:
Dim rstCountry As Recordset
Set rstCountry = New Recordset


how can "New Recordset" be bad?
(Invaild use of new?)

I need a vacation.

Invalid Use Of New Keyword
hello,

i tried to connect vb6 and mysql using the ODBC connector. I made a form that inserts data to the database:

Here is my code:

Code:

Private Sub cmdSave_Click()
Dim sql As String
sql = "INSERT INTO tblcourse(c_name) VALUES(' " & txtcrs.Text & " ')"
execQuery (sql)
MsgBox "Course has been saved.", , "Add a new course."
End Sub


im using modules for my connection and here is the code

Code:

'---------------------------------------
'My connection
'---------------------------------------
Public Const dsn = "myconnector"
Public Const DB = "db_ams"


when i compile, there is an error and points to this line.


Code:

Public Sub execQuery(qStr As String)
Dim szCon As New Connection ' <---- error
szCon.Open dsn
szCon.Execute qStr
Do While szCon.State = adStateExecuting
DoEvents
Loop
szCon.Close
End Sub


I dont know if im lacking something here. Thank you in advance

Compile Error: Invalid Use Of New Keyword
Hello,

I have the same routine working in a another class file and it's working there. But here not.

Call:

Code:
Set objResults = New Results
AddToResultset strFileName, objResults
I do get the compile error on line "Set objField = New Field". But I don't understand why? Why is it not possible to make a new instance of Field?


Code:
Private Sub AddToResultset(ByVal strFileName As String, _
ByRef objResults As Results)

Dim objResult As Result
Dim objField As Field

Set objResult = New Result
Set objField = New Field

objField.Name = "FileName"
objField.Value = strFileName
objResult.Fields.Add objField

objResults.Add objResult

Set objField = Nothing
Set objResult = Nothing

End Sub
Thanks in advance.

Nico.

Help With Compile Error Invalid Use Of New Keyword
i make a program and when i run this i have this problem i tried to make the exe file and have the same problem, what is this, and how can i put and end in this?

Compile Error (Invalid Use Of New Keyword) RESLOVED
Hi, i am using this code to connect to the database

Public Sub OpenConnection()
On Error GoTo ErrMess
Screen.MousePointer = vbHourglass
Set db = New Connection

worked fine, until i added some forms and modules from a previous project and i am now gettin

Compile Error
Invalid Use of New Kayword

this is at the "set db= New Connection"

Any help on y i am getting this,

Thanks Adam

&"Invalid Use Of New Keyword&" Error On CR Form
whenever crystal report form is loaded i get compile error "Invalid use of New keyword"
on "Set con=new connection"

slowpoison786@gmail.com
"Work like you don't need the money, Love like you've never been hurt."

New Dictionary &"Invalid Use Of New Keyword&"
Please help,

I have this server/client chat interface I am trying to write, but the Dictionary references I have give me an error. Here is some of the code:
In Global Declarations:

Option Explicit
Dim hostname As String
Dim nameindex As New Dictionary <== "invalid use of new keyword" error
Dim indexindex As New Dictionary <== "invalid use of new keyword" error
Dim sendindex1 As New Dictionary <== "invalid use of new keyword" error
Dim sendindex2 As New Dictionary <== "invalid use of new keyword" error
Dim connection As Boolean
Dim exists As Integer
Dim current As String

Does anyone know why it is not functioning correctly?!?!?

Thanks,

XMan51

ANSI SQL Keyword For Jet SQL Keyword
What is the official ANSI keyword for Jet SQL DATETIME?

How To Say (Does Text1.text Contain This Keyword? Keyword= &"hello&")
if there a way to say

for example

does text1.text contain "hello" amount other words....

so does text1.text contain this keyword within it's text.... if keyword found then replace keyword with another word

Is There A 'this' Keyword In VB?
I was just trying to make a program using some classes and usually in Java I would use the 'this' keyword to pass a reference to the current object in a method to another object. Is it possible to do this in VB?

Also while we're at it I may as well as if the 'super' keyword exists in VB?

Using End Keyword
I've heard several times on this forum that using End to stop or exit a program is a bad idea. Why exactly is this?

Note: I tried searching but ended up getting completely unrelated threads.

KeyWord
How can Assign an event to F2, F3, F4,F5 and so........

Thanks....

How To Use Between Keyword In VB
I have some text boxes say text1, text2 and text3. i want to check if the value of text1 lies in between va;ues given in text2 and text3. including the values given in text2 and text3........

Any Keyword
I have noticed that Vb has an Any keyword, Most commonly seen in API.


VB Code:
Public Declare Function AddAccessDeniedAce Lib "advapi32.dll" ( _                        pAcl As ACL, _                        ByVal dwAceRevision As Long, _                        ByVal AccessMask As Long, _                        pSid As [b]Any[/b]) _                        As Long


Does this mean ANY data type? Also, is there anway i can use outside of the API. An example would be appreciated

Thanks

Jenova

Mod Keyword?
Now im not sure here, but i thought the mod keyword would return if a number was a multiple of another number

if a mod 8 = 0 then

but it seems to only be able to do odds and evens?

Also, is there a way to have a loop only do even numbers of the loop? like

a() = split(mystr,vbcrlf)

For a = 0 to ubound(a) mod 2

?

Nothing Keyword
Hi
I have the follow code:


Code:
Set nPicture = NewPicture


If NewPicture is Nothing, how can i verify this in my code?
I try the follow


Code:

If NewPicture <> Nothing
...
End If



But does'nt work.
Any help?

Thanks
Daniel

The Me Keyword :)
I noted something funny about the Me keyword today. As you all may know (at least after reading this post ) the ME keyword can be used to denote an object inside that object. For e.g. if you use the keyword Me in a form's code, it will refer to that form, in a class module, it will refer to that class and so on. Now look at the following code:


Code:
'Inside a class module
Public Property Get SomeProperty() As String
SomeProperty = mSomeProperty
End Sub

Private Property Let SomeProperty(ByVal vSomeProperty As String)
mSomeProperty = vSomeProperty
End Sub

'The above procedures create a Property that's read-only outside the class module

Public Sub TestProperty(ByVal strTest As String)
Me.SomeProperty = strTest 'This Fails!!
SomeProperty = strTest 'This works
MsgBox Me.SomeProperty
End Sub


So when you use the Me keyword in a module, it's treated just as if the module were being accessed from outside

.

New Keyword
Trying to use CoSetProxyBlanket API in my OCX as in the following article...

http://support.microsoft.com/default.aspx?scid=KB;en-us;q249636

Problem is when I get to the
Code:
Set MyUnk = New MyLib.MyClass
line, the 'MyClass' that I need to use is not available. If I type it in I get 'Invalid use of New keyword'

How do I get round this, or can't I??

'Mod' Keyword
What is that? For instance:
VB Code:
If MyInteger Mod 2 = 0 Then


Thanks
Tom

NEW Keyword
what makes an object able to be declared as new??

for example you can do

Dim FileSys as NEW FileSystemObject

but not

Dim cmdButton as NEW CommandButton

so what determines what can and what can't?

New Keyword
I'm working with VBA in Excel.

If I insert the following statement into a module and save the Workbook as version 5.0/95 when I reopen the workbook the line is missing.

Dim objWkb as New Workbook

This doesn't happen if I remove the New keyword or if I save the workbook as a Microsoft Excel Workbook (I'm running Excel 2000).

Thanks for the help.

How Do You Use The LIKE Keyword
Basically I'm deisgning a database proggy in VB which uses Access (its for a college assignment). My question is, how the hell do you use the LIKE keyword, whats the correct syntax?

Thanx

WITH Keyword?
Hi everybody,

THanx everybody for helping me out.

Regards,

Samir.

Using The 'Or' Keyword ...
Basically, what does the 'Or' keyword do? And how does the program decide which one to use if you type 'Or' ?

thanx~!

AND Keyword
Can I use the AND keyword in an SQL statement? For example, this statement I put together gives an error, what would the correct syntax be?

"SELECT * FROM [table1] WHERE [Field1] >= 50 AND WHERE [Field2] >=50 ORDER BY [Field3]"

Thanking you in advance...

When To Use SET Keyword With NEW?
What is the correct way to use SET and NEW? When I declare a NEW ADODB.RecordSet ex. Set rs = New ADODB.Recordset I know I have to use the NEW keyword but what about when I use Dim itemX As ListItem, why don't I hae to use NEW here as well ex. Set itemX = ListView1.ListItems.Add(, , rs.Fields(0), , 1).

Set Keyword
why is the 'set' keyword used in vb6 in defining objects. And how is this different from usind dim and new?

thanks

Help Keyword? ^_^
Im Back VB With More Questions!

1.How Do I Make It Where I Move The Crusor Over An Item On My Form And A Tanish,Yellow Small Box Pops Up Where The Crusor Is And Says Something Like This...

"This Button Will Make You Lose Weight!"

On Delphi Its Called HelpKeyword But This Is VB So I Dont Know...

Thanks..
SoUrCeCoDe!

How To Use The Sql Keyword
please do tell me how to import a particular unique field(e.g. id#) in my form. I use the "count" keyword in my sql statement, with the specific command and yet is not displaying the way i it to? please do help?

New Keyword
I was just wondering why you can do things like:

dim x as ListImages

but then when you say

set x = new ListImages

you get a bad use of new keyword?

So many things you can declare but you can't new, hence you can't use.

Is there anyway to do this?

Thanks
Ian

New Keyword
I've got a question on technical interview:
What happens in 2 situations after objMyObject was set to nothing:
1. You have this code:

Dim objMyObject as clsMyClass 'there is a reference to clsMyClass
set objMyObject = new clsMyClass
'do some stuff with an object
set objMyObject = nothing



I answered that objMyObject is destroyed and memory is freed.

2. You have this code:

Dim objMyObject as new clsMyClass

'do some stuff with an object
set objMyObject = nothing



My answer was the same. Interviewer was not agree. He said that just after Set objMyObject = Nothing in a second case a new object will be created instead of destroyed one.
Is he correct?
Vlad

_NewEnum Keyword
What is the _NewEnum keyword?
What does it mean/refer to?
It can be found in the VB6 object browser inside the Collection Class

'* I saw this sample from a book


Code:
Public Property Get NewEnum() As IUnknown
Set NewEnum = m_custCollection.[_NewEnum]
End Property

Is this to implement a For Each loop feature in the collection class?

thanks

ByVal Keyword
Out of interest, I'm wondering why this would be used; at all.

My assumption on how it works, based on discussion I've come across:

ByRef is more efficient as it's just parsing the memory address of the varible being parsed to it. So when the program uses the varible it just looks it up by pointing to where the address tells it that it's located.

Whereas ByVal creates another varible in the memory, then reads the value of the varible being parsed to it and stores it in the new varible. And then the new varible is used through the section of code. This takes more time as it has to allocate another varible, aswell as set it.

So why would you use ByVal? The only thing I've seen that says you should specifically to use ByVal, is in API calls that are declared 'As Any'.

Post feedback/thoughts.

VBA &amp; OOP - Objects And The New Keyword
Hello everyone,

I don't have a strong command of the terminology related to OOP, but I'll try to formulate my question as clear as possible.

I'm trying to find a way in order to make objects created by a user defined class not to appear in the IntelliSense dropdown list after the "New" keyword, much in the way the class Range in Word can't be instantiated like "Set OneRange = New Range", but raher setting a reference to a property of a different object that returns a Range object (Set OneRange = Activedocument.Range)...

Besides, I'd like to hear any feedback about "VBA Developer's Handbook (2nd Edition) " by Ken Getz and Mike Gilbert. I already own O'Reilly's "VB/VBA in a Nutshell", which is a superb reference book, but what I'm after is a work that can teach me VBA intermediate/advanced topics and specially regarding custom classes and object models.

Please Give Me An Example Of Using The Any Keyword
A declaration, a procedure call, statement, any-thing.

Keyword As An Identifier
I'm wondering if there is a way to use a keyword as the name of an identifier (the name of a class property in this case).

I'm asking because I'm working on a wrapper class for CDO.Message (from CDO for Win2k) and I'm working on wrapping the "To" property, but since this is a VB keyword I can't create a property with that name.

Is there any way to get around this?

Keyword + Space?
Hi again, this is just a quick and hopefully short thread!

just what chiefredbull said, and what I wanted to know, would I use the


Code:
+ " "
in order to tell it to make sure that it highlights a keyword with a space, so that not ALL the words/particular keywords in a word get highlighted?

for example:


Code:
Do Until lCurWordPos = 0
'Colour it red
rtf1.SelStart = lCurWordPos - 1
rtf1.SelLength = Len(w(c) + " ")
rtf1.SelColor = vbRed
rtf1.SelText = LCase(w(c)+ " ")
' Find the next occurance of the word
lCurWordPos = InStr(lCurWordPos + 1, LCase$(rtf1.Text+ " "), LCase$(w(c))+ " ")
DoEvents
Loop
like that?

Optional Keyword ?
Can someone tell me what is wrong here?
I am useing the optional keyword in my args list and since i have inserted them i am getting a Compile Error, it is saying that -->

Procedure declaration does not match description of event or procedure having the same name

Here is the code on form1 -- (this is the one that gets highlighted)
---------------------------------------------------------------------------------
Private Sub Sockets_OpenAdbConnection(intWhichInfo, Optional intIndex As Integer, Optional sUserN As String, Optional sUserP As String, Optional sUfriends As String)

Here is the code on form2
--------------------------------------------------------------------------------
Public Event OpenAdbConnection(ByVal intWhichInfo, ByVal intIndex As Integer, ByVal sUserN As String, ByVal sUserP As String, ByVal sUfriends As String)

*(Different calls to this procedure use different args)

How To Detect The Keyword?
How to detect if the keyword is present in a textbox?

Help! Getting An Error When Using The New Keyword.
When running my application I get the following compile error when calling a module:
Invalid use of New keyword.
I looked at the MSDN help and it seems that I have used it correctly. Here is the line of code that is giving me a problem:
Set AgentControl = New Agent
where agent was set like this:
Public WithEvents AgentControl As Agent
Under the Option Explicit in the class module.
Anyone have any idea what I am doing wrong?

Keyword Matching
could anyone pls tell me ,

if i want to match the paragraph in a text area with the keywords that are stored in my database , what should i do for the coding ??

for example , i'm marking an essay , it is in the text area .. and i need to check whether the essay contains any of the keywords that are stored in the database ... what should i do .. and once found the keywords , count the number of keyword matches ..

Keyword Matching
i've once posted this question .. and received a responsed ..
however .. i'm not good in VB .. and not clear about what are they explaining to me about ...

i'm asking again .. i want to know how can i match the paragraph in a text area with the selected keywords in MS.access ??

it's hard for me to understand , therefore i hope someone could come up with a simple example of it .. i mean , a working example in VB .. just a simple one will do ..

Thanks in advance ..

ON ERROR-keyword
hey everybody,

In order to avoid closing of application while running,I have kept this thing,

Private form1 sub()
On Error GOTO ErrDesc
---
---
---
errdesc:Msgbox err.errdescription

so if any error occurs it displays automatically the corresponding error.

But THe PROBLEM is when there is no ERRor also it gives an empty message box.So how to avoid this.

PLZ HELP.

Access And The LIKE Keyword
I am coming across a problem using the LIKE keyword.
My app is using an ADO connection aceesing an acces db retruning recordsets

"Select * from tblInfo Where POSID=" i

works fine but once I add in the Like the SQL

"Select * from tblinfo WHERE Description LIKE '"& strVar &"*' AND posId= "& i

I know the SQL works in access and it seems to excecute fine but returns EOF BOF all the time.

i apologize for any typo's in my code, I am retyping this sitting beside my own computer right now (not on the network)

How do I fix this ?
thanks

Keyword Conflict In ADO
I am trying to edit a database in Visual Basic 6, that someone else created with another piece of software.

The old software (that is still used) used DAO, but my software uses ADO.

Here's the problem, there is one field which holds the value of the number of temperatures a test was run under, and the field's name is "NOT." When I set my sql statement, I get an error becasue my unintentional NOT operator is missing an expression.

I have looked at teh old code, and apparently, the DAO code didnt require the sql statement, so there was no problem.

I am under the impression that mixing DAO and ADO can be a bad idea, and I already have a substantial amount of ADO code written in the project, so presumably, I need to be able to handle a database field called NOT in ADO.

Anyone?

Keyword Search
Hi , kindly help me out. How can i make this program??? I have a rich text box with some text. There are few keywords in a listbox , on clicking the listbox item , All the corresponding keywords in the textbox would be highlighted which are equal to word in the listbox. Similarly as i keep on clicking the words in the listbox , any corresponding words , if they are there in the textbox , then they keep on getting highlighted.
cheers and thanks in advance

Copyright 2005-08 www.BigResource.com, All rights reserved