vb2010通讯录源代码(vb个人通讯录程序设计)
admin 发布:2022-12-19 03:25 120
今天给各位分享vb2010通讯录源代码的知识,其中也会对vb个人通讯录程序设计进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
急求一个用VB制作通讯录的步骤及源码
Private Sub Combo1_Click()
Label1.Caption = Format("姓名:", "!@@@@@@@@@@@@@@") Format("电话号码:", "!@@@@@@@@@@@@@@") Chr(13) _
Format(Combo1.Text, "!@@@@@@@@@@@@@@") Format(Combo2.Text, "!@@@@@@@@@@@@@@")
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Combo1.AddItem Combo1.Text, 0
Combo1.SelStart = 0
Combo1.SetFocus
End If
End Sub
Private Sub Combo2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Combo2.AddItem Combo2.Text, 0
Combo2.SelStart = 0
Combo2.SetFocus
End If
End Sub
通讯录代码 C语言 跪求
#include stdio.h
#include stdlib.h
#include string.h
#include conio.h
#define N 100 void input();//添加新用户函数
void amend();//修改用户信息函数
void delete_client();//删除用户信息函数
void demand_client();//用户信息查询函数
void collect_telephone();//用户信息汇总函数
void save_client(struct telephone message);//保存函数
void demand_name();//按用户名查询
void demand_telephone();//按电话号码查询
struct telephone
{
char client_name[20];
char client_address[30];
char client_telephone[15];
}; //添加新用户函数
void input()
{
struct telephone message;
char reply='y';
char save='y';
while (reply=='y')
{ printf("用户姓名:");
scanf("%s",message.client_name);
printf("电话号码:");
scanf("%s",message.client_telephone); save_client(message);
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //保存函数
void save_client(struct telephone message)
{
FILE *fp;
fp=fopen("message.dat","a+");
if (fp!=NULL)
{
fwrite(message,sizeof(struct telephone),1,fp);
}
else
{
printf("\n打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
} //修改用户信息函数
void amend()
{
struct telephone message;
FILE *fp;
char amend_name[20];
char reply='y';
char found='y';
char save='y';
int size=sizeof(struct telephone);
while (reply=='y')
{
found='n';
fp=fopen("message.dat","r+w");
if (fp!=NULL)
{
system("cls");
printf("\n请输入要修改的姓名:");
scanf("%s",amend_name);
while ((fread(message,size,1,fp))==1)
{
if ((strcmp(amend_name,message.client_name))==0)
{
found='y';
break;
}
}
if (found=='y')
{ printf("==========================================\n");
printf("\n用户姓名:%s\n",message.client_name);
printf("\n电话号码:%s\n",message.client_telephone);
printf("==========================================\n");
printf("修改用户信息:\n");
printf("\n用户姓名:");
scanf("%s",message.client_name); printf("\n电话号码:");
scanf("%s",message.client_telephone);
printf("\n要保存吗?(y/n):");
scanf(" %c",save);
if (save=='y')
{
fseek(fp,-size,1);
fwrite(message,sizeof(struct telephone),1,fp);
}
}
else
{
printf("无此人信息!\n");
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //删除用户信息函数
void delete_client()
{
struct telephone message[N];
struct telephone temp_str;
struct telephone delete_str;
int i=0,j=0;
char reply='y';
char found='y';
char confirm='y';
char delete_name[20];
FILE *fp;
while (reply=='y')
{
system("cls");
fp=fopen("message.dat","r");
if (fp!=NULL)
{
i=0;
found='n';
printf("\n请输入姓名:");
scanf("%s",delete_name);
while ((fread(temp_str,sizeof(struct telephone),1,fp))==1)
{
if ((strcmp(delete_name,temp_str.client_name))==0)
{
found='y';
delete_str=temp_str;
}//查找要删除的记录
else
{
message[i]=temp_str;
i++;
}//将其它无关记录保存起来
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
if (found=='y')
{
printf("==========================================\n");
printf("用户姓名:%s\n",delete_str.client_name);
printf("电话号码:%s\n",delete_str.client_telephone);
printf("==========================================\n");
}
else
{
printf("无此人信息,按任意键返回……\n");
getchar();
break;
}
printf("确定要删除吗?(y/n):");
scanf(" %c",confirm);
if (confirm=='y')
{
fp=fopen("message.dat","w");
if (fp!=NULL)
{
for(j=0;ji;j++)
{
fwrite(message[j],sizeof(struct telephone),1,fp);
}
printf("记录已删除!!!\n");
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
}
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
}
//用户信息查询函数
void demand_client()
{
int choice=1;
while (choice!=3)
{
system("cls");
printf("电话查询菜单\n");
printf(" 1 按联系人姓名查询\n");
printf(" 2 按联系人电话号码查询\n");
printf(" 3 返回主菜单\n");
printf("请选择(1-3):");
scanf("%d%*c",choice);
if (choice3)
{
printf("请输入1-6之间的整数\n");
printf("按任意键返回菜单……\n");
getchar();
continue;
}
if (choice==1)
{
demand_name();
}
else if (choice==2)
{
demand_telephone();
}
}
} //按用户名查询
void demand_name()
{
struct telephone message;
FILE *fp;
char amend_name[20];
char reply='y';
char found='y';
while (reply=='y')
{
found='n';
fp=fopen("message.dat","r+w");
if (fp!=NULL)
{
system("cls");
printf("\n请输入姓名:");
scanf("%s",amend_name);
while ((fread(message,sizeof(struct telephone),1,fp))==1)
{
if ((strcmp(amend_name,message.client_name))==0)
{
found='y';
break;
}
}
if (found=='y')
{ printf("==========================================\n");
printf("用户姓名:%s\n",message.client_name); printf("电话号码:%s\n",message.client_telephone);
printf("==========================================\n");
}
else
{
printf("无此人信息!\n");
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //按电话号码查询
void demand_telephone()
{
struct telephone message;
FILE *fp;
char telephone[20];
char reply='y';
char found='y';
while (reply=='y')
{
found='n';
fp=fopen("message.dat","r+w");
if (fp!=NULL)
{
system("cls");
printf("\n请输入电话号码:");
scanf("%s",telephone);
while ((fread(message,sizeof(struct telephone),1,fp))==1)
{
if ((strcmp(telephone,message.client_telephone))==0)
{
found='y';
break;
}
}
if (found=='y')
{ printf("==========================================\n");
printf("用户姓名:%s\n",message.client_name); printf("电话号码:%s\n",message.client_telephone);
printf("==========================================\n");
}
else
{
printf("无此电话号码的有关信息!\n");
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //用户信息汇总函数
void collect_telephone()
{
struct telephone message;
FILE *fp;
fp=fopen("message.dat","r");
if (fp!=NULL)
{
system("cls");
printf("\n用户姓名\t\t电话号码\n");
while ((fread(message,sizeof(struct telephone),1,fp))==1)
{
printf("\n%-24s",message.client_name); printf("%-12s\n",message.client_telephone);
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("按任意键返回主菜单……\n");
getch();
} void main()
{
char choice[10]="";
int len=0;
while (choice[0]!='7')
{ printf("\t==========电话本号码查询系统=============\n"); printf("\t\t 1、添加新联系人\n");
printf("\t\t 2、修改联系人信息\n");
printf("\t\t 3、删除联系人信息\n");
printf("\t\t 4、联系人信息查询\n");
printf("\t\t 5、联系人信息汇总\n");
printf("\t\t 7、退出\n");
printf("\t=========================================\n");
printf("请选择(1-7):");
scanf("%s",choice);
len=strlen(choice);
if (len1)
{
printf("请输入1-6之间的整数\n");
printf("按任意键返回主菜单……\n");
getchar();
getchar();
continue;
} switch (choice[0]) {
case '1':
input();
break;
case '2':
amend();
break;
case '3':
delete_client();
break;
case '4':
demand_client();
break;
case '5':
collect_telephone();
break; default:
break;
}
}
}
用C语言做通讯录
这看你是怎样定义的了。如果你50个同学是用结构体来定义的话就比较容易实现。用二维数组的话,就比较麻烦。
查找名字可以用strcmp(输入的名字,编好的名字)==0如果相等,就等于查找到你输入的名字了。记录它的下标,再输出它的联系方式。
下面是一个比较完整的通讯录代码,你参考一下啦。(看到专家两个字,我真没资格去回答你了,汗)
/*10.3.2源程序*/
/******头文件(.h)***********/
#include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*标准库函数*/
#include "string.h"/*字符串函数*/
#include "ctype.h" /*字符操作函数*/
#define M 50 /*定义常数表示记录数*/
typedef struct /*定义数据结构*/
{
char name[20]; /*姓名*/
char units[30]; /*单位*/
char tele[10]; /*电话*/
}ADDRESS;
/******以下是函数原型*******/
int enter(ADDRESS t[]); /*输入记录*/
void list(ADDRESS t[],int n); /*显示记录*/
void search(ADDRESS t[],int n); /*按姓名查找显示记录*/
int delete(ADDRESS t[],int n); /*删除记录*/
int add(ADDRESS t[],int n); /*插入记录*/
void save(ADDRESS t[],int n); /*记录保存为文件*/
int load(ADDRESS t[]); /*从文件中读记录*/
void display(ADDRESS t[]); /*按序号查找显示记录*/
void sort(ADDRESS t[],int n); /*按姓名排序*/
void qseek(ADDRESS t[],int n); /*快速查找记录*/
void copy(); /*文件复制*/
void print(ADDRESS temp); /*显示单条记录*/
int find(ADDRESS t[],int n,char *s) ; /*查找函数*/
int menu_select(); /*主菜单函数*/
/******主函数开始*******/
main()
{
int i;
ADDRESS adr[M]; /*定义结构体数组*/
int length; /*保存记录长度*/
clrscr(); /*清屏*/
for(;;)/*无限循环*/
{
switch(menu_select()) /*调用主菜单函数,返回值整数作开关语句的条件*/
{
case 0:length=enter(adr);break;/*输入记录*/
case 1:list(adr,length);break; /*显示全部记录*/
case 2:search(adr,length);break; /*查找记录*/
case 3:length=delete(adr,length);break; /*删除记录*/
case 4:length=add(adr,length); break; /*插入记录*/
case 5:save(adr,length);break; /*保存文件*/
case 6:length=load(adr); break; /*读文件*/
case 7:display(adr);break; /*按序号显示记录*/
case 8:sort(adr,length);break; /*按姓名排序*/
case 9:qseek(adr,length);break; /*快速查找记录*/
case 10:copy();break; /*复制文件*/
case 11:exit(0); /*如返回值为11则程序结束*/
}
}
}
/*菜单函数,函数返回值为整数,代表所选的菜单项*/
menu_select()
{
char s[80];
int c;
gotoxy(1,25);/*将光标定为在第25行,第1列*/
printf("press any key enter menu......\n");/*提示压任意键继续*/
getch(); /*读入任意字符*/
clrscr(); /*清屏*/
gotoxy(1,1);
printf("********************MENU*********************\n\n");
printf(" 0. Enter record\n");
printf(" 1. List the file\n");
printf(" 2. Search record on name\n");
printf(" 3. Delete a record\n");
printf(" 4. add record \n");
printf(" 5. Save the file\n");
printf(" 6. Load the file\n");
printf(" 7. display record on order\n");
printf(" 8. sort to make new file\n");
printf(" 9. Quick seek record\n");
printf(" 10. copy the file to new file\n");
printf(" 11. Quit\n");
printf("***********************************************\n");
do{
printf("\n Enter you choice(0~11):"); /*提示输入选项*/
scanf("%s",s); /*输入选择项*/
c=atoi(s); /*将输入的字符串转化为整型数*/
}while(c11); /*选择项不在0~11之间重输*/
return c; /*返回选择项,主程序根据该数调用相应的函数*/
}
/***输入记录,形参为结构体数组,函数值返回类型为整型表示记录长度*/
int enter(ADDRESS t[])
{
int i,n;
char *s;
clrscr(); /*清屏*/
printf("\nplease input num \n"); /*提示信息*/
scanf("%d",n); /*输入记录数*/
printf("please input record \n"); /*提示输入记录*/
printf("name unit telephone\n");
printf("------------------------------------------------\n");
for(i=0;in;i++)
{
scanf("%s%s%s",t[i].name,t[i].units,t[i].tele); /*输入记录*/
printf("----------------------------------------------\n");
}
return n; /*返回记录条数*/
}
/*显示记录,参数为记录数组和记录条数*/
void list(ADDRESS t[],int n)
{
int i;
clrscr();
printf("\n\n*******************ADDRESS******************\n");
printf("name unit telephone\n");
printf("------------------------------------------------\n");
for(i=0;in;i++)
printf("%-20s%-30s%-10s\n",t[i].name,t[i].units,t[i].tele);
if((i+1)%10==0) /*判断输出是否达到10条记录*/
{
printf("Press any key continue...\n"); /*提示信息*/
getch(); /*压任意键继续*/
}
printf("************************end*******************\n");
}
/*查找记录*/
void search(ADDRESS t[],int n)
{
char s[20]; /*保存待查找姓名字符串*/
int i; /*保存查找到结点的序号*/
clrscr(); /*清屏*/
printf("please search name\n");
scanf("%s",s); /*输入待查找姓名*/
i=find(t,n,s); /*调用find函数,得到一个整数*/
if(in-1) /*如果整数i值大于n-1,说明没找到*/
printf("not found\n");
else
print(t[i]); /*找到,调用显示函数显示记录*/
}
/*显示指定的一条记录*/
void print(ADDRESS temp)
{
clrscr();
printf("\n\n********************************************\n");
printf("name unit telephone\n");
printf("------------------------------------------------\n");
printf("%-20s%-30s%-10s\n",temp.name,temp.units,temp.tele);
printf("**********************end***********************\n");
}
/*查找函数,参数为记录数组和记录条数以及姓名s */
int find(ADDRESS t[],int n,char *s)
{
int i;
for(i=0;in;i++)/*从第一条记录开始,直到最后一条*/
{
if(strcmp(s,t[i].name)==0) /*记录中的姓名和待比较的姓名是否相等*/
return i; /*相等,则返回该记录的下标号,程序提前结结束*/
}
return i; /*返回i值*/
}
/*删除函数,参数为记录数组和记录条数*/
int delete(ADDRESS t[],int n)
{
char s[20]; /*要删除记录的姓名*/
int ch=0;
int i,j;
printf("please deleted name\n"); /*提示信息*/
scanf("%s",s);/*输入姓名*/
i=find(t,n,s); /*调用find函数*/
if(in-1) /*如果in-1超过了数组的长度*/
printf("no found not deleted\n"); /*显示没找到要删除的记录*/
else
{
print(t[i]); /*调用输出函数显示该条记录信息*/
printf("Are you sure delete it(1/0)\n"); /*确认是否要删除*/
scanf("%d",ch); /*输入一个整数0或1*/
if(ch==1) /*如果确认删除整数为1*/
{
for(j=i+1;jn;j++) /*删除该记录,实际后续记录前移*/
{
strcpy(t[j-1].name,t[j].name); /*将后一条记录的姓名拷贝到前一条*/
strcpy(t[j-1].units,t[j].units); /*将后一条记录的单位拷贝到前一条*/
strcpy(t[j-1].tele,t[j].tele); /*将后一条记录的电话拷贝到前一条*/
}
n--; /*记录数减1*/
}
}
return n; /*返回记录数*/
}
/*插入记录函数,参数为结构体数组和记录数*/
int add(ADDRESS t[],int n)/*插入函数,参数为结构体数组和记录数*/
{
ADDRESS temp; /*新插入记录信息*/
int i,j;
char s[20]; /*确定插入在哪个记录之前*/
printf("please input record\n");
printf("************************************************\n");
printf("name unit telephone\n");
printf("--------------------------------------------------\n");
scanf("%s%s%s",temp.name,temp.units,temp.tele); /*输入插入信息*/
printf("------------------------------------------------\n");
printf("please input locate name \n");
scanf("%s",s); /*输入插入位置的姓名*/
i=find(t,n,s); /*调用find,确定插入位置*/
for(j=n-1;j=i;j--) /*从最后一个结点开始向后移动一条*/
{
strcpy(t[j+1].name,t[j].name); /*当前记录的姓名拷贝到后一条*/
strcpy(t[j+1].units,t[j].units); /*当前记录的单位拷贝到后一条*/
strcpy(t[j+1].tele,t[j].tele); /*当前记录的电话拷贝到后一条*/
}
strcpy(t[i].name,temp.name); /*将新插入记录的姓名拷贝到第i个位置*/
strcpy(t[i].units,temp.units); /*将新插入记录的单位拷贝到第i个位置*/
strcpy(t[i].tele,temp.tele); /*将新插入记录的电话拷贝到第i个位置*/
n++; /*记录数加1*/
return n; /*返回记录数*/
}
/*保存函数,参数为结构体数组和记录数*/
void save(ADDRESS t[],int n)
{
int i;
FILE *fp; /*指向文件的指针*/
if((fp=fopen("record.txt","wb"))==NULL) /*打开文件,并判断打开是否正常*/
{
printf("can not open file\n");/*没打开*/
exit(1); /*退出*/
}
printf("\nSaving file\n"); /*输出提示信息*/
fprintf(fp,"%d",n); /*将记录数写入文件*/
fprintf(fp,"\r\n"); /*将换行符号写入文件*/
for(i=0;in;i++)
{
fprintf(fp,"%-20s%-30s%-10s",t[i].name,t[i].units,t[i].tele);/*格式写入记录*/
fprintf(fp,"\r\n"); /*将换行符号写入文件*/
}
fclose(fp);/*关闭文件*/
printf("****save success***\n"); /*显示保存成功*/
}
/*读入函数,参数为结构体数组*/
int load(ADDRESS t[])
{
int i,n;
FILE *fp; /*指向文件的指针*/
if((fp=fopen("record.txt","rb"))==NULL)/*打开文件*/
{
printf("can not open file\n"); /*不能打开*/
exit(1); /*退出*/
}
fscanf(fp,"%d",n); /*读入记录数*/
for(i=0;in;i++)
fscanf(fp,"%20s%30s%10s",t[i].name,t[i].units,t[i].tele); /*按格式读入记录*/
fclose(fp); /*关闭文件*/
printf("You have success read data from file!!!\n"); /*显示保存成功*/
return n; /*返回记录数*/
}
/*按序号显示记录函数*/
void display(ADDRESS t[])
{
int id,n;
FILE *fp; /*指向文件的指针*/
if((fp=fopen("record.txt","rb"))==NULL) /*打开文件*/
{
printf("can not open file\n"); /*不能打开文件*/
exit(1); /*退出*/
}
printf("Enter order number...\n"); /*显示信息*/
scanf("%d",id); /*输入序号*/
fscanf(fp,"%d",n); /*从文件读入记录数*/
if(id=0idn) /*判断序号是否在记录范围内*/
{
fseek(fp,(id-1)*sizeof(ADDRESS),1); /*移动文件指针到该记录位置*/
print(t[id]); /*调用输出函数显示该记录*/
printf("\r\n");
}
else
printf("no %d number record!!!\n ",id); /*如果序号不合理显示信息*/
fclose(fp); /*关闭文件*/
}
/*排序函数,参数为结构体数组和记录数*/
void sort(ADDRESS t[],int n)
{
int i,j,flag;
ADDRESS temp; /*临时变量做交换数据用*/
for(i=0;in;i++)
{
flag=0; /*设标志判断是否发生过交换*/
for(j=0;jn-1;j++)
if((strcmp(t[j].name,t[j+1].name))0) /*比较大小*/
{
flag=1;
strcpy(temp.name,t[j].name); /*交换记录*/
strcpy(temp.units,t[j].units);
strcpy(temp.tele,t[j].tele);
strcpy(t[j].name,t[j+1].name);
strcpy(t[j].units,t[j+1].units);
strcpy(t[j].tele,t[j+1].tele);
strcpy(t[j+1].name,temp.name);
strcpy(t[j+1].units,temp.units);
strcpy(t[j+1].tele,temp.tele);
}
if(flag==0)break; /*如果标志为0,说明没有发生过交换循环结束*/
}
printf("sort sucess!!!\n"); /*显示排序成功*/
}
/*快速查找,参数为结构体数组和记录数*/
void qseek(ADDRESS t[],int n)
{
char s[20];
int l,r,m;
printf("\nPlease sort before qseek!\n"); /*提示确认在查找之前,记录是否已排序*/
printf("please enter name for qseek\n"); /*提示输入*/
scanf("%s",s); /*输入待查找的姓名*/
l=0;r=n-1; /*设置左边界与右边界的初值*/
while(l=r) /*当左边界=右边界时*/
{
m=(l+r)/2; /*计算中间位置*/
if(strcmp(t[m].name,s)==0) /*与中间结点姓名字段做比较判是否相等*/
{
print(t[m]); /*如果相等,则调用print函数显示记录信息*/
return ; /*返回*/
}
if(strcmp(t[m].name,s)0) /*如果中间结点小*/
l=m+1; /*修改左边界*/
else
r=m-1; /*否则,中间结点大,修改右边界*/
}
if(lr) /*如果左边界大于右边界时*/
printf("not found\n"); /*显示没找到*/
}
/*复制文件*/
void copy()
{
char outfile[20]; /*目标文件名*/
int i,n;
ADDRESS temp[M]; /*定义临时变量*/
FILE *sfp,*tfp; /*定义指向文件的指针*/
clrscr();/*清屏*/
if((sfp=fopen("record.txt","rb"))==NULL) /*打开记录文件*/
{
printf("can not open file\n"); /*显示不能打开文件信息*/
exit(1); /*退出*/
}
printf("Enter outfile name,for example c:\\f1\\te.txt:\n"); /*提示信息*/
scanf("%s",outfile); /*输入目标文件名*/
if((tfp=fopen(outfile,"wb"))==NULL) /*打开目标文件*/
{
printf("can not open file\n"); /*显示不能打开文件信息*/
exit(1); /*退出*/
}
fscanf(sfp,"%d",n); /*读出文件记录数*/
fprintf(tfp,"%d",n);/*写入目标文件数*/
fprintf(tfp,"\r\n"); /*写入换行符*/
for(i=0;in;i++)
{
fscanf(sfp,"%20s%30s%10s\n",temp[i].name,temp[i].units,
temp[i].tele); /*读入记录*/
fprintf(tfp,"%-20s%-30s%-10s\n",temp[i].name,
temp[i].units,temp[i].tele); /*写入记录*/
fprintf(tfp,"\r\n"); /*写入换行符*/
}
fclose(sfp); /*关闭源文件*/
fclose(tfp); /*关闭目标文件*/
printf("you have success copy file!!!\n"); /*显示复制成功*/
}
好好参考一下啦,可能有些函数你还没学到,找找书就行了。
高分求用VB做的通讯录+源代码
如果你平时有许多同学和朋友的信息,试试在电脑上编写一个我这样的通讯录。很方便的哟。 先新建一个工程,在“工具箱-右键-部件”添加“Microsoft windows common control 6.0”,然后在窗体上添加五个标签,“标题”分别为 “姓名、电话、Oicq、E-Mail、地址”;添加一个文本框(text1), 然后[复制/粘贴4次]使其成为控件数组;添加一个Listview控件(Listview1),在其属性框中,添加五个“列首”,“文本”值分别为“姓名、电话、Oicq、E-Mail、地址”,“查看属性”为 “3-lvwReport”, 选中“整行选择”,取消“隐藏选择”;添加两个按钮,其标题属性分别为“添加”、“删除”。添加如下代码:
Option Explicit
Dim fileName As String
Private Sub Command1_Click()
’将文本框中的信息添加到列表框中
Dim i As Integer
With ListView1.ListItems.Add()
.Text = Text1(0)
For i = 1 To 4
.SubItems(i) = Text1(i)
Next i
End With
End Sub
VB通讯录代码
Public panduan As Integer
Private Sub Combo1_Click()
Data1.Recordset.MoveFirst
Data1.Recordset.FindFirst "姓名='" Combo1.Text "'"
Call xianshi
End SubPrivate Sub Combo2_Click()
Data2.Recordset.MoveLast
Data2.Recordset.FindLast "时间='" Combo2.Text "'"
Call xianshi2
End SubPrivate Sub Command1_Click()
If Data1.Recordset.AbsolutePosition = Data1.Recordset.RecordCount - 1 Then
MsgBox "已经到最后一条记录", 0 + 16, "警告"
Exit Sub
Else
Data1.Recordset.MoveNext
Combo1.Text = Data1.Recordset("姓名")
Call xianshi
End If
End SubPrivate Sub Command10_Click()
If Command10.Caption = "写日记" Then
Text11.Text = ""
Combo2.Text = Text12.Text
Command10.Caption = "保存"
Else
With Data2
.Recordset.AddNew.Recordset("时间") = Text12
.Recordset("事件") = Text11
.Recordset.Update
End With
Combo2.Clear
Data2.Refresh
Call chushihua2
Call xianshi2
Command10.Caption = "写日记"
End If
End SubPrivate Sub Command11_Click()
a = MsgBox("当前记录将被删除,确定吗?", 4 + 48, "警告")
If a = vbNo Then Exit Sub
Data2.Recordset.Delete
Data2.Refresh
Combo2.Clear
Call chushihua2
End SubPrivate Sub Command12_Click()
Data2.Recordset.MoveLast
Combo2.Text = Data2.Recordset("时间")
Call xianshi2
End SubPrivate Sub Command13_Click()
If Data2.Recordset.AbsolutePosition = 0 Then
MsgBox "这已经是最为古老的日记了", 0 + 16, ""
Exit Sub
Else
Data2.Recordset.MovePrevious
Combo2.Text = Data2.Recordset("时间")
Call xianshi2
End If
End SubPrivate Sub Command14_Click()
If Data2.Recordset.AbsolutePosition = Data2.Recordset.RecordCount - 1 Then
MsgBox "这已经是最新的一篇了", 0 + 16, "警告"
Exit Sub
Else
Data2.Recordset.MoveNext
Combo2.Text = Data2.Recordset("时间")
Call xianshi2
End If
End SubPrivate Sub Command2_Click()
panduan = 1
If Command2.Caption = "添加" Then
Command1.Enabled = False
Command3.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
Command2.Caption = "保存数据"
Text2.Visible = True
Text3.Visible = True
Text4.Visible = True
Text5.Visible = True
Text6.Visible = True
Text7.Visible = True
Text8.Visible = True
Text9.Visible = True
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""Else
If Text8.Text = "" Then
MsgBox "请输入完整数据!", 48, "警告"
Text8.SetFocus Else
a = MsgBox("当前记录将被添加,确定吗?", 4 + 48, "警告")
If a = vbNo Then
Command2.Caption = "添加"
Command1.Enabled = True
Command3.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Text2.Visible = False
Text3.Visible = False
Text4.Visible = False
Text5.Visible = False
Text6.Visible = False
Text7.Visible = False
Text8.Visible = False
Text9.Visible = False
Exit SubElse
Command2.Caption = "添加"
Command1.Enabled = True
Command3.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Data1.Recordset.Edit
With Data1
.Recordset.AddNew
.Recordset("姓名") = Text8.Text
.Recordset("手机号") = Text2
.Recordset("性别") = Text3
.Recordset("工作单位") = Text4
.Recordset("职务") = Text5
.Recordset("电子邮箱") = Text6
.Recordset("联系地址") = Text7
.Recordset("QQ") = Text9
End With
Command2.Caption = "添加"
Text2.Visible = False
Text3.Visible = False
Text4.Visible = False
Text5.Visible = False
Text6.Visible = False
Text7.Visible = False
Text8.Visible = False
Text9.Visible = False
Combo1.Clear
Data1.Refresh
Call chushihua
Call xianshi
End If
End If
End If
End SubPrivate Sub Command3_Click()
If Command3.Caption = "修改" Then
Command1.Enabled = False
Command2.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
Command3.Caption = "保存修改"
Text2.Visible = True
Text3.Visible = True
Text4.Visible = True
Text5.Visible = True
Text6.Visible = True
Text7.Visible = True
Text8.Visible = True
Text9.Visible = TrueText2.Text = Label12.Caption
Text3.Text = Label13.Caption
Text4.Text = Label14.Caption
Text5.Text = Label15.Caption
Text6.Text = Label16.Caption
Text7.Text = Label17.Caption
Text8.Text = Combo1.Text
Text9.Text = Label18.Caption
Else
If Text8.Text = "" Then
MsgBox "请输入完整数据!", 48
Text8.SetFocusElse
a = MsgBox("当前记录将被修改,确定吗?", 4 + 48, "警告")
If a = vbNo Then
Command3.Caption = "修改"
Command1.Enabled = True
Command2.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Text2.Visible = False
Text3.Visible = False
Text4.Visible = False
Text5.Visible = False
Text6.Visible = False
Text7.Visible = False
Text8.Visible = False
Text9.Visible = False
Exit Sub
Else
Command3.Caption = "修改"
Command1.Enabled = True
Command2.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Data1.Recordset.Edit
With Data1
.Recordset("姓名") = Text8.Text
.Recordset("手机号") = Text2
.Recordset("性别") = Text3
.Recordset("工作单位") = Text4
.Recordset("职务") = Text5
.Recordset("电子邮箱") = Text6
.Recordset("联系地址") = Text7
.Recordset("QQ") = Text9
End With
Command3.Caption = "修改"
Text2.Visible = False
Text3.Visible = False
Text4.Visible = False
Text5.Visible = False
Text6.Visible = False
Text7.Visible = False
Text8.Visible = False
Text9.Visible = False
Combo1.Clear
Data1.Refresh
Call chushihua
Call xianshi
End If
End If
End If
End SubPrivate Sub Command4_Click()
If Command3.Caption = "保存修改" Or Command2.Caption = "保存数据" Then
Command3.Caption = "修改"
Command2.Caption = "添加"
Text2.Visible = False
Text3.Visible = False
Text4.Visible = False
Text5.Visible = False
Text6.Visible = False
Text7.Visible = False
Text8.Visible = False
Text9.Visible = False
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Combo1.Clear
Data1.Refresh
Call chushihua
Call xianshi
ElseEnd
End If
End SubPrivate Sub Command5_Click()
a = MsgBox("当前记录将被删除,确定吗?", 4 + 48, "警告")
If a = vbNo Then Exit Sub
Data1.Recordset.Delete
Data1.Refresh
Combo1.Clear
Call chushihua
End Sub Private Sub Command6_Click()
If Data1.Recordset.AbsolutePosition = 0 Then
MsgBox "已经到达第一条了", 0 + 16, ""
Exit Sub
Else
Data1.Recordset.MovePrevious
Combo1.Text = Data1.Recordset("姓名")
Call xianshi
End If
End SubPrivate Sub Command7_Click()
Data1.Recordset.MoveFirst
Combo1.Text = Data1.Recordset("姓名")
Call xianshi
End SubPrivate Sub Command8_Click()
Data1.Recordset.MoveLast
Combo1.Text = Data1.Recordset("姓名")
Call xianshi
End SubPrivate Sub Command9_Click()
Data1.Recordset.MoveFirst
Data1.Recordset.FindFirst "手机号='" Text10.Text "'"
Combo1.Text = Data1.Recordset("姓名")
If Data1.Recordset.NoMatch Then
MsgBox "查无此人!", 48, "注意"
ElseCall xianshi
End If
Call xianshi
End SubPrivate Sub Form_Initialize()
Data1.Refresh
Data2.Refresh
Call chushihua
Call chushihua2
End Sub
Sub gengxin()
Data1.Recordset.MoveFirst
Data1.Recordset.Update
Data1.Recordset.Edit
End Sub
Sub chushihua()
Data1.Recordset.MoveFirstDo While Data1.Recordset.EOF = False
Combo1.AddItem Data1.Recordset("姓名")Data1.Recordset.MoveNext
Loop
jlzs = Data1.Recordset.RecordCount
Text1.Text = jlzs
Data1.Recordset.MoveFirst
Combo1.Text = Data1.Recordset("姓名")Call xianshi
End SubPrivate Sub Form_Load()
Data1.DatabaseName = "db1.mdb"
Data2.DatabaseName = "db2.mdb"
Data1.RecordSource = "表2"
Data2.RecordSource = "表1"
Dim jlzs As IntegerEnd Sub
Private Sub Combo1_keyup(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Data1.Recordset.MoveFirst
Data1.Recordset.FindFirst "姓名='" Combo1.Text "'"
Combo1.Text = Data1.Recordset("姓名")
If Data1.Recordset.NoMatch Then
MsgBox "查无此人!", 48, "注意"
ElseCall xianshi
End If
End If
End SubSub xianshi()Label8.Caption = "当前记录号:" Data1.Recordset.AbsolutePosition + 1
End Sub
Sub xianshi2()
Text11 = Data2.Recordset("事件")
End SubSub chushihua2()
Data2.Recordset.MoveFirstDo While Data2.Recordset.EOF = False
Combo2.AddItem Data2.Recordset("时间")
Text11 = Data2.Recordset("事件")
Data2.Recordset.MoveNext
LoopData2.Recordset.MoveFirst
Combo2.Text = Data2.Recordset("时间")
Text11 = Data2.Recordset("事件")
Call xianshi
End Sub
Private Sub Text10_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Data1.Recordset.MoveFirst
Data1.Recordset.FindFirst "手机号='" Text10.Text "'"
Combo1.Text = Data1.Recordset("姓名")
If Data1.Recordset.NoMatch Then
MsgBox "查无此人!", 48, "注意"
ElseCall xianshi
End If
End If
End Sub Private Sub Timer1_Timer()
If Label19.Left + Label19.Width 0 Then
Label19.Move Label19.Left - 20
Else
Label19.Left = Form1.ScaleWidth
End If
End SubPrivate Sub Timer2_Timer()
Text12.Text = Now
End Sub
用VB做通讯录?有查询,添加,删除功能的!
用VB做通讯录 2007-07-10 00:41
分类:软件编程 字号: 大大 中中 小小 如果你平时有许多同学和朋友的信息,试试在电脑上编写一个我这样的通讯录。很方便的哟。 先新建一个工程,在“工具箱-右键-部件”添加“Microsoft windows common control 6.0”,然后在窗体上添加五个标签,“标题”分别为 “姓名、电话、Oicq、E-Mail、地址”;添加一个文本框(text1), 然后[复制/粘贴4次]使其成为控件数组;添加一个Listview控件(Listview1),在其属性框中,添加五个“列首”,“文本”值分别为“姓名、电话、Oicq、E-Mail、地址”,“查看属性”为 “3-lvwReport”, 选中“整行选择”,取消“隐藏选择”;添加两个按钮,其标题属性分别为“添加”、“删除”。添加如下代码:
Option Explicit
Dim fileName As String
Private Sub Command1_Click()
'将文本框中的信息添加到列表框中
Dim i As Integer
With ListView1.ListItems.Add()
.Text = Text1(0)
For i = 1 To 4
.SubItems(i) = Text1(i)
Next i
End With
End Sub
Private Sub Command2_Click()
'删除列表框中信息
If ListView1.ListItems.Count 0 Then
If MsgBox("真的要删除吗?", vbQuestion + vbYesNo + vbDefaultButton2) = vbYes Then
ListView1.ListItems.Remove ListView1.SelectedItem.Index
End If
End If
End Sub
Private Sub Form_Load()
Dim tpStr As String, i As Integer
fileName = App.Path "\data.txt"
If Dir(fileName) "" Then
'加载数据
Open fileName For Input As #1
Do While Not EOF(1)
With ListView1.ListItems.Add()
For i = 0 To 4
Line Input #1, tpStr
If i = 0 Then
.Text = tpStr
Else
.SubItems(i) = tpStr
End If
Next i
End With
Loop
Close #1
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
Dim tpList As ListItem
'保存数据
Open fileName For Output As #1
For Each tpList In ListView1.ListItems
Print #1, tpList.Text
For i = 1 To 4
Print #1, tpList.SubItems(i)
Next i
Next tpList
Close #1
End Sub
本程序已在windows98+VB6.0环境下调试通过。
vb2010通讯录源代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vb个人通讯录程序设计、vb2010通讯录源代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-08如何创建个人网页,如何创建个人网址
- 05-07pb超级报表源代码(pb报表工具)[20240507更新]
- 05-07简历源代码可以上传照片的简单介绍[20240507更新]
- 05-07广告切换源代码免费下载(广告切换源代码免费下载安装)[20240507更新]
- 05-06阁楼网源代码(阁楼是什么网站)[20240506更新]
- 05-06源代码管理资源管理器(资源管理器运行代码)[20240506更新]
- 05-06人脸识别源代码pdf的简单介绍[20240506更新]
- 05-06包含超市管理系统java源代码的词条[20240506更新]
- 05-06商城app源代码免费(商城App源码)[20240506更新]
- 05-06包含游戏源代码不同的模式的词条[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接