Link to home
Start Free TrialLog in
Avatar of Peter Chan
Peter ChanFlag for Hong Kong

asked on

Issue to field

Hi,
When I've put other value to H column, and then pressed 3rd column, I do not know why the relevant value in H column does change to 1 by itself (see attached file)?TW SO number creator.xlsm
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

The code in the workbook is password protected. Please provide the password or attach an unprotected workbook.
Yes I can but I'm sorry but I can't help you since this involves Access.

I added Access to your topics so that someone with knowledge of Access can help you.
What a mess ....

You are calling the Read_Text_File function wich overwrite everything in the worksheet, ehence your data "reset".
Can you explain in details what this button is supposed to do ?

Second, get rid of those performance ehencing instructions till your code produce the desired results.
"Premature optimization is the root of all evil (or at least most of it) in programming." (Donald Knuth,December 1974).

Next:
- Choose meaningfull names for your variables.
- Lots of unused variables.
- What's the purpose of the Para_Message parameter you wrote in many functions ?
Most of the time, it is useless.
- Your functions don't do what their name suggest (Read_Text_File that read a database).
- Your functions break the SRP (Single Responsibility Principle).
- The Save button is useless as it Reproduce the workbook_BeforeSave event.
- Use built-in constant as much as possible, it has more meaning.
- Give up hungarian notation, it provide nothing usefull.
- Avoid global variable, unless you have a very good reason to use them (here, you have none).
- In the database, choose accurate data type for your columns (numbers are not text).
- You don't need to sort data to validate them, it slow things down a lot.
- In your previous posts, I already fixed many things in your workbook. Why do you keep uploading an obsolête one ?
- Taking advantage of the ribbon by moving your buttons in the ribbon might be a wise idea, as it save space.
when your excel file loads it reads a table in your access db and copies it to your excel file to col J    
On click button of Get Next Number 
if col 7<= col 6 or Col 8 >10 or <1 then out of range

else
  if nothing in col 9 then col 6
  else col 9

if col9+ col8<= col 7
  col9 = col9 + col8
else out of range

set col10 to nothing
for loop to the valuein col8
 if col 10 nothing then
  col10 = col9+1
else
 col 10 = col10 & " " col9 + loop counter


hope that helps a bit?


Give up hungarian notation, it provide nothing usefull.
I strongly disagree. A variable named intMyVariable is self-documenting in that you know without looking at the declaration for the variable that it's an Integer.
Second, get rid of those performance ehencing instructions till your code produce the desired results 

Where are these instructions? 
Where are these instructions?  
Application.ScreenUpdating ...

I strongly disagree. A variable named intMyVariable is self-documenting in that you know without looking at the declaration for the variable that it's an Integer.
Hungarian notation turn the developper into a data type checker, while the compiler do that job much better (in other words: this is not the developper 's job).

It is tough to read.

When you have a variable that does not cover the whole value range of a type (in other words: there are differences between what the type suggest and what the usage allow), the self documentation become a source of error (integer can't describe a positive value, a byte can't describe a bit mask, ect ...). And nothing document better than a name describing the variable's role (a data type is not a role).
:
If you are afraid of scrolling up many pages to see a variable's type, it probably mean your function (or procedure) is too long, does too many things (in other words, it break the SRP) and must be broken into several smaller ones.

A simple "fix" is to declare variable right before the first use.

*Irony ON*
Dim Lrow as long
What is a "long row" ? Can you define it ?
If a long row exist, a short row must exist as well. What's the difference between a long and a short row ?
Is a long row longer than the shortest row of the long rows ?
Is a short row shorter than the longest row of the short rows ?
*Irony OFF*
If you are afraid of scrolling up many pages to see a variable's type....
The point is that with Hungarian Notation you never have to scroll no matter how long or short the procedure is.

But I'll shut up now.
Avatar of Peter Chan

ASKER

Problem to me now is, I put other number (not 1) to H column, and press button "Get Next Number/Set", the number in H column does change to 1 by itself. What is the reason of this?
ASKER CERTIFIED SOLUTION
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial