hi , my problem with comm port in device manager,when i using serial rs232 to send data to port first time when i switch on the pc
it execute the program ,But when i use USB to Serial Adapter cable to send data it work's fine but again i want to use RS232 to send data ,then it 's say the invalid port number in my program .i am using Com1 for both in device manager.I tryed with com2 for Rs232 it say's invalid port number i aslo changed in the commport =2 in my code.
i am using Mscomm1 in vb6 ,
When i plug usb to serial it keep the com1 with it.not allowing to other to use it . I removed usb to serial plug and tryed using com1 for rs232 it won't work it say 's invalid port num ,When i start pc first time it will work for Rs232 without USb to Serial whenipluged usb cable it will wont allow to rs232 to use comm 1.
About ARRAy
also have problem with array if i inistalize Dynamic array() then use
redim array to allocate some array to it like (0 to 4 ) to send the byte to port is this array will stop exeuting in loop when it send 4 byte to port in continously .Thus we can add many elements to 0th element of the array like
(0)=1
(0)=2
(0)=3thus it will store diffferent value in the 0 element of the array or we hv to allocate different element for each different data to store like (0)=1
(1)=2
(2)=3 this way .In my code i using 4 function calling each of the function in one another to continously to display value from port in progressbar . Like 2 call in 1 ,3 call in 2,4 call in 3 ,1 call in 4 like a loop .
All the 4 func are in the loop ,befor "loop until condition" this stament of the loop ,i have called the another function to execute .
function1()
do
byte(0)=&h62 to the port
byte(1)=&h62 to the port
call function2()
loop until condition func 2 willl call 3..
My Problem is i assigned 100 of array for each function. it was excuting properly but after some time it stop looping the code that 100 of array was over then i assign 150 of array it again executing properly .If i use Redim statement then i have not to assign many array for it which it stop looping.
I want to clear some doubt
1.how the array values r stored in the array
2.how the Redim is used
3.when we execute some program in vb thus it again assign the array from the starting value thatis 0 to 100 (in program)or it start from remaining of the array which has to be allocate in the memory.
4.Can we refresh the array which is alerady asign to the some variables that again we have not to asign it.
If Any confusion then pls ask .thank u.

Dani AI

Generated

A concise, practical follow-up to the two issues raised by (COM-port conflicts when a USB-to-serial adapter is used, and unexpected VB6 dynamic-array behavior). was right to ask for clearer steps — below are concrete checks and fixes that address both problems without rehashing the original post.

Start with the COM-port conflict

  • Inspect Device Manager -> Ports (COM & LPT) and note which device shows which COM number. If the USB adapter claims the same COM as the physical RS232, change the adapter to an unused COM: Properties -> Port Settings -> Advanced -> COM Port Number.
  • Use View -> Show hidden devices in Device Manager and uninstall any ghosted or duplicate COM entries. Replug the adapter and reboot if necessary.
  • In VB6, always close the port before changing its number and reopen it after setting; add error trapping so an "invalid port" condition is detected rather than silently ignored.

Safe MSComm sequence (VB6)

If MSComm1.PortOpen Then MSComm1.PortOpen = False
MSComm1.CommPort = 3          ' set an available COM number
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True

Arrays, Redim, and scope — clear answers to the four doubts

  • Array storage: each element holds a single value; assigning the same index again overwrites the previous value. To store sequential values, use an increasing index or a dynamic container.
  • ReDim basics: ReDim arr(n) allocates (default lower bound 0 unless changed). ReDim Preserve arr(n) resizes while keeping existing data; ReDim without Preserve clears contents. Erase arr frees a dynamic array.
  • Lifetime/scope: arrays declared inside a procedure are reinitialized each call unless Static or module-level. Program restart always resets memory.
  • Growing arrays: to append without losing data, use ReDim Preserve or use a Collection/linked buffer; note ReDim Preserve can only change the last dimension.

Design note: the nested, re-entrant call pattern described can hide errors and make index/port state hard to follow. A single loop or simple state machine plus logging of Err.Number/Err.Description and port open/close state will make debugging far easier.

Recommended Answers

All 2 Replies

Jatinder,
Whenever I open your thread to answer I feel jittery. Do you know why?. It is because of the way you have presented your problem. I can understand your urgency. But you should restrain from adding one after another your problems in one thread itself. It is very difficult to assimilate.

Now you and your Com Port trouble.

You are using USB as well as Serial. OK. In your Program you make changes to send and receive data through these devices, right?. And you as the user replace tha cable accordigly? ha! or your program select a port and use the device attached? or it select a device, come, what may be the port. What is true in this?

Think... Think much more.. you will definitely get the answer.

About the array, it seems you have earlier started a thread. I am unable to make out anything of it. Please explain it line by line what you want actually to establish.

sorry manoharan,i could not presented my Que's properly .
thank u for showing my mistake.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.