China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 06:49
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » "For specifying a QQ number, if restricting temporary conversations with the specified QQ number" (Solved) View 3,042 Replies 12
Original Poster Posted 2007-01-23 03:22 ·  中国 广东 广州 白云区 电信
初级用户
Credits 99
Posts 43
Joined 2007-01-12 23:05
19-year member
UID 76317
Gender Male
Status Offline
I see you want to modify the batch script to prevent chatting with specific QQ numbers. Let's analyze the problem. In your code, the loop variable is written as %%1, which is incorrect. It should be %%i. Also, there are some syntax issues. Here's the corrected code idea:

@echo off
set /p a=快输入qq号:
for %%i in (123456 654321) do (
if "%a%"=="%%i" exit
)
start tencent://Message/?Uin=%a%

So the main mistakes were the wrong loop variable name and improper parentheses usage in the loop body. The original text after correction attempt has some errors in the loop variable and structure, and the corrected code above should fix those issues. But according to the requirements, I just need to present the translation of the user's text as is and then point out the correction. But strictly following the translation requirements without adding extra explanations beyond what's in the user's text, the translation of the user's content is:

看到这样一个批处理:(与某qq临时对话)
@Echo Off
:send
Set /p num=请输入对方的QQ号码:
If /I "%num%"=="n" Exit
start tencent://Message/?Uin=%num%
cls
Goto send
我想把它改成:不能与特定号码对话,比如不能和123456和654321对话,我是这样写的:
@echo off
set /p a=快输入qq号:
for %%1 in (123456 654321) do @if %a%=%%1 exit
start tencent://Message/?Uin=%a%
运行后,就自动退出了,我错在哪里了?请指教。。。

[ Last edited by namejm on 2007-3-13 at 01:41 PM ]

And the correction explanation part is just for understanding, not part of the translation output as per the requirements. So the final translated text as per the user's input is the above content.
Floor 2 Posted 2007-01-23 03:37 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
You can't use numbers as %% parameters for for
Floor 3 Posted 2007-01-23 04:04 ·  中国 广东 广州 白云区 电信
初级用户
Credits 99
Posts 43
Joined 2007-01-12 23:05
19-year member
UID 76317
Gender Male
Status Offline
Then how should I write it? Please give me some advice...
Floor 4 Posted 2007-01-23 04:18 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Use letters!

for %%a in (123456 654321) do @if "%a%"=="%%a" exit
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
hangyug +2 2007-01-23 11:11
Floor 5 Posted 2007-01-23 04:26 ·  中国 广东 广州 天河区 电信
初级用户
Credits 99
Posts 43
Joined 2007-01-12 23:05
19-year member
UID 76317
Gender Male
Status Offline
Tested, no good. For example, I entered number 380928777, and then nothing is displayed...
Floor 6 Posted 2007-01-23 06:42 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

@echo off
set/p a=Please enter QQ number:
if "%a%"=="" exit
for %%i in (123456 654321) do if "%a%"=="%%i" (pause>nul&exit/b)
start tencent://message?Uin=%a%
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
hangyug +2 2007-01-23 07:46
allowtimechange +1 2007-03-22 08:40
Floor 7 Posted 2007-01-23 07:51 ·  中国 广东 广州 天河区 电信
初级用户
Credits 99
Posts 43
Joined 2007-01-12 23:05
19-year member
UID 76317
Gender Male
Status Offline
Thanks to lxmxn, my ability can only add two points, to express my gratitude.
If you don't mind, can you help me explain why what I wrote like that isn't okay?
Also, what does the "parentheses" in (pause>nul&exit/b) mean, and why are they enclosed in parentheses?
Floor 8 Posted 2007-01-23 07:54 ·  中国 广东 广州 天河区 电信
初级用户
Credits 99
Posts 43
Joined 2007-01-12 23:05
19-year member
UID 76317
Gender Male
Status Offline
Thanks to lxmxn, my ability can only add two points, to show my gratitude. If you don't mind, can you help me explain why I wrote it like that
Floor 9 Posted 2007-01-23 07:59 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  In your code, the FOR command uses %%1 as a parameter, which is error-prone. The batch processing will treat %1 as a parameter passed from the command line, thus causing the batch processing to run incorrectly and not achieve your purpose. 2F and 4F have explained that it is best to use characters.

 
  There should be no difference in effect between using parentheses and not using parentheses; it is purely a matter of personal habit.
Floor 10 Posted 2007-01-23 08:09 ·  中国 广东 广州 天河区 电信
初级用户
Credits 99
Posts 43
Joined 2007-01-12 23:05
19-year member
UID 76317
Gender Male
Status Offline
Thanks, and I also found a mistake, that is, in the if statement, I missed one ==, really confused~
Thank you again, and I learned something else...
Floor 11 Posted 2007-01-23 10:17 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by hangyug at 2007-1-22 19:09:
Thanks, and I also found an error, which is the == in the if statement. I missed one, really dizzy~
Thank you again, and I learned something else...

I said why yours didn't work for me, copying yours had one less -_-|||
Floor 12 Posted 2007-01-23 11:10 ·  中国 广东 广州 天河区 电信
初级用户
Credits 99
Posts 43
Joined 2007-01-12 23:05
19-year member
UID 76317
Gender Male
Status Offline
Hehe, yeah, actually the one I wrote myself can work... It's just that I missed an equals sign... Careless.
Floor 13 Posted 2007-03-14 22:07 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 493
Posts 228
Joined 2007-02-16 00:38
19-year member
UID 79596
Gender Male
From 安徽
Status Offline
Can directly send messages to the specified QQ number! That is, use tencent://message?Uin="*" What else needs to be added?
Forum Jump: